4

The picture pretty much says it all. I have a string that is null and I cannot get my user with it. However if I type null it works.

Weirdest error

I did this workaround that works but I cannot see how it should be needed enter image description here

I did see see something about nullable primitives and EF 6 (I am using EF6) but this is a string.

Anyone has any idea why?


Update

As can be seen here I use UseCSharpNullComparisonBehavior = true; I have now tried both on Azure and a SQL Express.

Odd thing is that this works on the live system, we have done some development since but nothing as far as i know that should affect this.

I also updated to the latest EF from nuget.

enter image description here

Rickard Liljeberg
  • 966
  • 1
  • 12
  • 39

1 Answers1

6

Check out this question:

How can i query for null values in entity framework?

Essentially it is caused by the fact that Entity Framework is translating your lambda expression to SQL. The explicit null you entered is triggering EF to do an IS NULL comparison in SQL

EDIT:

since your using EF 6, it looks like this will work if you set your context to allow the use of null comparisons, For Example:

objectContext.ContextOptions.UseCSharpNullComparisonBehavior = true;
Community
  • 1
  • 1
Adam Oakley
  • 786
  • 8
  • 15
  • Right I found that post earlier but since it said it was fixed in EF6 I did not think that was it. Also I already have UseCSharpNullComparisonBehavior set on my context. – Rickard Liljeberg Mar 27 '15 at 19:00
  • I double checked that UseCSharpNullComparisonBehavior is set to true. I run against azure. Wonder if that makes any difference. – Rickard Liljeberg Mar 27 '15 at 19:08
  • I have now tried on local SQL express, same problem. Strange this is it works on the live version (100 work hours have gone in from live system) but nothing about contexts or similar has changed. It also works on another system with very similar code. – Rickard Liljeberg Mar 27 '15 at 19:58