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 ...
FROM category, eventcategories WHERE category.parent = eventcategories.parent
(which returns empty recordset if category.parent is null), whereas the second ... WHERE eventcategories.parent IS NULL
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With