Workaround for Linq-to-SQL:
var result = from entry in table
where entry.something.Equals(value)
select entry;
Workaround for Linq-to-Entities (ouch!):
var result = from entry in table
where (value == null ? entry.something == null : entry.something == value)
select entry;
This is a nasty bug which has bitten me several times. If this bug has affected you too, please visit the bug report on UserVoice and let Microsoft know that this bug has affected you as well.
Edit: This bug is being fixed in EF 4.5! Thanks everyone for upvoting this bug!
For backwards compatibility, it will be opt-in - you need manually enable a setting to make entry == value
work. No word yet on what this setting is. Stay tuned!
Edit 2: According to this post by the EF team, this issue has been fixed in EF6! Woohoo!
We changed the default behavior of EF6 to compensate for three-valued logic.
This means that existing code that relies on the old behavior (null != null
, but only when comparing to a variable) will either need to be changed to not rely on that behavior, or set UseCSharpNullComparisonBehavior
to false to use the old broken behavior.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…