title: Entity Framework select from link table with list
body: <p>Using the following database table structure:</p>
  
  <p><strong>Order</strong> Table:</p>
  
  <pre><code>OrderId
  OrderName
  </code></pre>
  
  <p><strong>OrderItem</strong> Table:</p>
  
  <pre><code>OrderId
  ItemId
  </code></pre>
  
  <p><strong>Item</strong> Table:</p>
  
  <pre><code>ItemId
  ItemName
  </code></pre>
  
  <p>I have an 'Order' entity that has an 'Items' collection. What I need to do is return all orders that contain certain items. Example: All orders with items with id: 1, 4 and 5 (I don't care if it has other items as well). I currently have the selected id's in a List object (it doesn't have to be a list though). I have tried various ideas with 'contains' method but to no avail.</p>
  
  <p>Because OrderItem is a link table, I can't access it as an entity itself. If I could then presumably I could do:</p>
  
  <pre><code>context.OrderItems.Where(m =&gt; selectedIds.Contains(m.ItemId))
  </code></pre>
  
  <p>or something like that.</p>
  
  <p>Is there a way of doing this in a single query without having to loop around the results?</p>
  
  <p>Thanks</p>