score:2

Accepted answer

You can create new LINQ expressions containing old expressions.

var loc = (from l in Entity.Locations select l);

if (hasLocation)
    loc = loc.Where(a => a.LocationId > 5);

if (hasName)
    loc = loc.Where(a => a.Name == "bla");

etc.

The expression is only evaluated once you use it, like var result = loc.ToList();


Related Articles