Yes, your problem will also arise if SQL. You must explicitly handle null, and this should work:
Where (parentID == null && c.ParentID == null) || (parentID == c.ParentID)
It is assumed that you need to match zero. If you want null to return all results without filtering, do this instead:
Where (parentID == null) || (parentID == c.ParentID)
I had problems with this even sometimes, and found how LINQ would translate correctly all the time:
Where (parentID == null) || (parentID != null && parentID == c.ParentID)
This is because even in SQL, if you execute ParentID = @ParentID , a null match does not return any results, and you must use ISNULL to avoid it being empty.
source share