Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Workaround for Linq-to-SQL:</p> <pre><code>var result = from entry in table where entry.something.Equals(value) select entry; </code></pre> <p>Workaround for Linq-to-Entities (ouch!):</p> <pre><code>var result = from entry in table where (value == null ? entry.something == null : entry.something == value) select entry; </code></pre> <p>This is a nasty bug which has bitten me several times. <strike>If this bug has affected you too, please visit the <a href="http://data.uservoice.com/forums/72025-ado-net-entity-framework-ef-feature-suggestions/suggestions/1015361-incorrect-handling-of-null-variables-in-where-cl?ref=title" rel="noreferrer">bug report on UserVoice</a> and let Microsoft know that this bug has affected you as well.</strike></p> <hr> <p><strong>Edit:</strong> <a href="http://data.uservoice.com/forums/72025-ado-net-entity-framework-ef-feature-suggestions/suggestions/1015361-incorrect-handling-of-null-variables-in-where-cl?ref=title#suggestion-1015361" rel="noreferrer">This bug is being fixed in EF 4.5</a>! Thanks everyone for upvoting this bug!</p> <p>For backwards compatibility, it will be opt-in - you need manually enable a setting to make <code>entry == value</code> work. No word yet on what this setting is. Stay tuned!</p> <hr> <p><strong>Edit 2:</strong> According to <a href="http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions/suggestions/1015361-incorrect-handling-of-null-variables-in-where-cl" rel="noreferrer">this post</a> by the EF team, <strong>this issue has been fixed in EF6! Woohoo!</strong></p> <blockquote> <p>We changed the default behavior of EF6 to compensate for three-valued logic.</p> </blockquote> <p>This means that existing code that relies on the old behavior <em>(<code>null != null</code>, but only when comparing to a variable)</em> will either need to be changed to not rely on that behavior, or set <a href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontextoptions.usecsharpnullcomparisonbehavior.aspx" rel="noreferrer"><code>UseCSharpNullComparisonBehavior</code></a> to false to use the old broken behavior.</p>
 

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