The trick to avoid filtering with null parameters in SQL was something like this:
select * from customers where (@CustomerName is null or CustomerName = @CustomerName)
This works well for me in LINQ to SQL:
string customerName = "XYZ"; var results = (from c in ctx.Customers where (customerName == null || (customerName != null && c.CustomerName == customerName)) select c);
But this above request, when in ADO.NET EF, does not work for me; it must be filtered by client name because it exists, but it is not. Instead, it queries all client records. Now this is a simplified example, because I have many fields with which I use this logic. But it never filters, does not request all records, and does not raise a timeout exception. But the strange thing is another request, does something similar, no problem.
Any ideas why? Does this seem to be a mistake for me, or is there a workaround for this? Since then, I have switched to extension methods that work.
Thanks.
source share