Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use UseCSharpNullComparisonBehavior for a single query?

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?

like image 293
adam0101 Avatar asked Feb 12 '23 13:02

adam0101


1 Answers

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;
like image 96
DavidG Avatar answered Feb 14 '23 01:02

DavidG