We have an EDMX-based EF6 application, where we'd like to run a LINQ query like this.
string category = ... // comes from somewhere and equals to null context.Product.Where(e => e.Category == category).ToArray();
The problem I see is that the generated SQL contains a
[table].[Category] = @p... in the where clause, regardless of the variable
null or not. So at the end of the day the query returns no results if the variable is
null, instead of generating a proper
is null criteria and return the proper rows.
I've tested with the explicit
e => e.Category == null expression and that does generate the
is null as expected.
I've also checked the EDMX and the SQL, and the corresponding
Category column is nullable indeed in both places, so that might not be the issue.
Any help would be appreciated.
Try to set
false. This is the property which affects the mentioned behavior.
See the documentation here