Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In SQL, NULL is not equal to NULL.</p> <p>You can interpret NULL as meaning: "there is value, but I don't know what it is". So if you're comparing two NULL values, you're really asking "is the first unknown value equal to the second unknown value?" Of course, there is no reason to assume they are, so SQL will say "no".</p> <p>I am assuming that this is causing your problem. You can verify that by looking at the actual SQL produced. If it's using the SQL = operator, this is indeed the problem. You can verify that by running the SQL in a database tool, such as SQL Management Studio in case you're using SQL Server.</p> <p>UPDATE:</p> <p>The condition</p> <pre><code>([Extent5].[MediaCategoryFormatID] = [Extent5].[MediaCategoryFormatID]) </code></pre> <p>will indeed return false when [Extent5].[MediaCategoryFormatID] is NULL.</p> <p>That answers the question "Why is it returning nothing?"</p> <p>However, another question come to mind: why would the entity framework generate that SQL from this linq query?</p> <p>I'm afraid that linq to entities is not exactly known for the quality of its SQL generation, and this case seems to confirm that. You might consider Linq to SQL. Even if that seems to be a dead-end track in the long run, the current implementation if a lot better than linq to entities.</p> <p>In either case, have you tried something like</p> <pre><code>someObjectList.Where(x =&gt; !item1.hasValue || x.SomeItem1.HasValue &amp;&amp; x.SomeItem1.Value == item1.Value) </code></pre> <p>Make sure to verify that under the profiler as well though, linq to entities might mess it up too.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload