Yes your problem would also occur if it's SQL. You have to handle null explicitly, and this should work:
Where (parentID == null && c.ParentID == null) || (parentID == c.ParentID)
This assumes that you want a null to match. If you want null to return all the results unfiltered, instead do:
Where (parentID == null) || (parentID == c.ParentID)
I've had trouble with this even sometimes, and found the way LINQ would translate correctly all the time was to do:
Where (parentID == null) || (parentID != null && parentID == c.ParentID)
This is because even in SQL, if you do where ParentID = @ParentID
, a null match returns no results, and you have to use ISNULL
to escape it to blank.