I’m seeing a strange behavior in an EF query adn I’m wondering why it is happening.
With the following code I don’t get any results:
if (category.Parent == null)
{
return Db.EventCategories.Where(c => c.Parent == category.Parent);
}
But with this code it does return the expected results:
if (category.Parent == null)
{
return Db.EventCategories.Where(c => c.Parent == null);
}
What is the difference? Isn’t null always null? or does the EF treats them as different elements when the value is a nullable (Parent is of type int?).
I’m not 100% sure, but I think the first statement generates something like
SELECT ...(which returns empty recordset if category.parent is null), whereas the secondFROM category, eventcategories WHERE category.parent = eventcategories.parent
... WHERE eventcategories.parent IS NULL.