Can I make a variable check for null in a LINQ query? If the variable is NULL then where does not filter.

 var select = from p in db.Products where p.Vendor == vendorId select p; 

where vendorId depends on the user's choice, and if he chose nothing, then the entire list is returned.

checking via if not appropriate, because there may be different variants of sample requests.

  • 2
    Frankly, I still do not understand why you can not check through if - eastwing

1 answer 1

 var select = from p in db.Products where vendorId == null || p.Vendor == vendorId select p;