Dynamic LINQ OR Conditions

linq

Solution

It sounds like your whitelist of names is only known at runtime. Perhaps try this:

string[] names = new string[] {"John", "foo", "bar"};

var matching = items.Where(x => names.Contains(x.Name));

Problem

I'm looking to use LINQ to do multiple where conditions on a collection similar to ``` IEnumerable<Object> items; items.Where(p => p.FirstName = "John"); items.Where(p => p.LastName = "Smith"); ``` except for rather than having multiple AND conditions (as with this example), I'd like to have multiple OR conditions. EDIT Sorry, to clarify I don't know how many of these conditions I will have so ``` items.Where(p => p.FirstName = "John" || p => p.LastName = "Smith") ``` won't work. Basically, here's what I'm trying to do: ``` foreach(var name in names) { items = items.Where(p => p.Name == name); } ```

Original source