title: Hitting the 2100 parameter limit (SQL Server) when using Contains()
body: <pre><code>from f in CUSTOMERS
  where depts.Contains(f.DEPT_ID)
  select f.NAME
  </code></pre>
  
  <p><code>depts</code> is a list (<code>IEnumerable&lt;int&gt;</code>) of department ids</p>
  
  <p>This query works fine until you pass a large list (say around 3000 dept ids) .. then I get this error:</p>
  
  <blockquote>
    <p>The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100.</p>
  </blockquote>
  
  <p>I changed my query to: </p>
  
  <pre><code>var dept_ids = string.Join(" ", depts.ToStringArray());
  from f in CUSTOMERS
  where dept_ids.IndexOf(Convert.ToString(f.DEPT_id)) != -1
  select f.NAME
  </code></pre>
  
  <p>using <code>IndexOf()</code> fixed the error but made the query slow. Is there any other way to solve this? thanks so much.</p>