How can I build logic upon supplied logic in a LINQ-to-Entities Where expression?
问题 I often come across, in LINQ for Entity Framework, a pattern where I add a .Where clause if a string value is specified, like: IQueryable<Foo> query = Foos.AsQueryable() if (!string.IsNullOrWhitespace(nameFilter)) query = query.Where(x => x.Name == name); if (!string.IsNullOrWhitespace(addressFilter) != null) query = query.Where(x => x.Address == addressFilter ); if (!string.IsNullOrWhitespace(cityFilter) != null) query = query.Where(x => x.City == cityFilter ); // ... I wanted to clean this