title: Using LINQ To Query Int Ids From An Array
body: <p>I have an array of Ids that I want to pass to the entity framework via a Linq query to return any matches</p>
  
  <p>I have written Linq queries that can convert Ids to strings and use the 'Contains' operator, such as:</p>
  
  <p>Model</p>
  
  <pre><code>public class Order {
    public long OrderId { get; set; }
    public string Name { get; set; } ...}
  
  Order[] orders = { new Order { OrderId = 123, Name = "Order1" }, new Order {...},...};
  </code></pre>
  
  <p>for which I can use something like:</p>
  
  <pre><code>long[] testArray = {123, 456};
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>var result = orders.Where(i =&gt; testArray.ToString().Contains(i.OrderId.ToString()));
  </code></pre>
  
  <p>but do I really need to keep casting the Ids to strings? It looks as though I can't access the 'Contains' if I keep them as ints.</p>
  
  <p>Ultimately, I want to be able to use this as part of a query that accesses the Entity Framework and so passes the query as part of an IQueryable&lt;> to make sure I am not returning reams of data when I only want a handfull, such as:</p>
  
  <pre><code>var orders = _repo.Orders().Where(i =&gt; orderArray.Contains(i.OrderId));
  </code></pre>
  
  <p>So any solution it would be useful if the query params (the int array) through the EF rather than getting all of the data and then checking it in memory.</p>
  
  <p>Cheers!</p>