Q: Combining Linq Queries with ANDs or Ors I have a problem as depicted below:
var customers = from c in ctx.Customers;

Dynamically from UI, I can pass a list of filters
Scenario 1. "AND"
groupOp = "AND"
filter 1: where c.ID == 1
filter 2: where c.Name == 'XYZ'

What I need is a way to combine
so end result is:
var filterList = from c in ctx.Customers
                 where c.ID == 1
                 && c.Name == 'XYZ'

Scenario 2. "OR" 
Same problem
var customers = from c in ctx.Customers;
Dynamically from UI, I can pass a list of filters
groupOp = "OR"
filter 1: where c.Name == 'ABC'
filter 2: where c.Name == 'XYZ'

What I need is a way to combine
so end result is:
var filterList = from c in ctx.Customers
                 where c.Name == 'ABC'
                 || c.Name == 'XYZ'

How can I dynamically combine the IQueryable with AND or OR. At the moment I have no requirement to combine AND and ORs so its just either AND or OR.
Any Help greatly appreciated always...

A: Use PredicateBuilder, i.e.
var predicate = PredicateBuilder.False<Customer>();
foreach (var filter in filters)
{
    predicate = predicate.Or(filter);
}
return ctx.Customers.Where(predicate);

If you don't want to manually build all the filter expressions manually in code, you might benefit from using the Dynamic Linq library build expressions from strings.
