I have a linq query function like (simplified):
public IList ListDocuments(int? parentID)
{
return (
from doc in dbContext.Docume
Literal null values are handled differently than parameters which could be null. When you explicitly test against null, the generated SQL will use the IS NULL operator, but when you're using a parameter it will use the standard = operator, meaning that no row will match because in SQL null isn't equal to anything. This is one of the more annoying .NET/SQL semantic mismatches in LINQ to SQL. To work around it, you can use a clause like:
where doc.ParentID == parentID || (doc.ParentID == null && parentID == null)