// The point is that it is hard to dynamically build a query with LINQ and/or // the extended classes that support LINQ. public List <Customer> CustomerQuery(string name, int minOrderCount) { List <Expression <Func <Customer, bool> > > conditions = new List <Expression <Func <Customer, bool> > >(); if (name != null) { conditions.Add(t => t.FirstName == "Steve"); } if (minOrderCount > 0) { conditions.Add(t => t.TotalOrdersPlaced > minOrderCount); } using (AcmeDatabase db = database()) { var customers = db.Customers.AsQueryable(); foreach (var condition in conditions) { customers = customers.Where(condition); } return(customers.ToList()); } }
public List <Customer> AwesomeCustomers() { using (AcmeDatabase db = database()) { return((from c in db.Customers where c.TotalOrdersPlaced > 500 orderby c.FirstName select c).ToList()); } }