How to do an “in” query in entity framework?

Try this:

var orderKeys = new int[] { 1, 12, 306, 284, 50047};
var orders = (from order in context.Orders 
              where orderKeys.Contains(order.Key);
              select order).ToList();
Assert.AreEqual(orderKeys.Count, orders.Count);

Edit: I have found some workarounds for this issue – please see WHERE IN clause?:

The Entity Framework does not
currently support collection-valued
parameters (‘statusesToFind’ in your
example). To work around this
restriction, you can manually
construct an expression given a
sequence of values using the following
utility method:

Leave a Comment