Can I use UseCSharpNullComparisonBehavior for a single query?

c# entity-framework entity-framework-6 sql-server

Question

I have a query that used to be a stored procedure and was converted to an EF query. It is timing out now. Using SQL Profiler, I can see the only difference in the SQL generated is the new behavior where EF turns entity.Property == value into (entity.Property = @value OR (@value IS NULL AND entity.Property IS NULL)).

I know I can turn this off for the entire context by setting UseCSharpNullComparisonBehavior = false, but I really only want to do it for this one query. Is that possible?

Or, is there a way to write the EF query so it doesn't generate the SQL like this?

1
4
11/13/2014 11:35:09 PM

Accepted Answer

You can set the UseDatabaseNullSemantics property of your context to true. That is essentially the reverse of the old ObjectContext.UseCSharpNullComparisonBehavior property.

context.Configuration.UseDatabaseNullSemantics = true;
8
11/14/2014 3:30:53 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow