With the following code how do I get a return that includes any of zip list but only records that have a purpose of street address? This currently returns matches for either the zip or the street address.
var zipPredicate = PredicateBuilder.False<NameAddress>();
List<string> zips = new List<string>();
zips.Add("90210");
zips.Add("90211");
foreach (var item in zips)
{
zipPredicate = zipPredicate.Or(n=> n.ZIP.Contains(item));
}
zipPredicate = zipPredicate.And(n=> n.Purpose=="Street Address");
var zipResult = from s in NameAddresses
.AsExpandable()
.Where(zipPredicate)
select new{s.ID, s.ZIP, s.Purpose};
zipResult.Dump();
I think what you are looking for is:
EDIT
One more thing as well, if you want to drop building up the predicate, you should be able to do something like:
.Where(n=>zips.Contains(n.ZIP) && n.Purpose=="Street Address")The important piece is that your entity property component comes inside the .Contains(). This would shorten your code to:Which I like better for readability. I would expect the query that ends up getting executed is the same either way.