title: Linq2Sql -> Searching the database against a local collection of values - "Queries with local collections are not supported"
body: <p>I am running up against the wall with Linq2SQL. I love it, its amazing the flexibility, but I have run up against interesting hangups. I hope its just my lack of knowledge of it, and there really is a solution.  Take for example... a linq2sql query like this:</p>
  
  <p>// some local collection of ids</p>
  
  <pre><code>var terminalID = new List&lt;int&gt;(){1, 2, 3, 4, 5};
  </code></pre>
  
  <p>// a part of a Linq statement:</p>
  
  <pre><code>queryDataIDs.Where(q =&gt; q.DataEventKeyID == 2 &amp;&amp; terminalID.Contains((int)q.ValueDecimal));
  </code></pre>
  
  <p>will result in an error @ runtime</p>
  
  <pre><code>"NotSupportedException was unhandled"
  "Queries with local collections are not supported"
  </code></pre>
  
  <p>Stack:</p>
  
  <pre><code>at System.Data.Linq.SqlClient.SqlBinder.Visitor.ConvertToFetchedSequence(SqlNode node)
     at System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitAlias(SqlAlias a)
     at System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
     at System.Data.Linq.SqlClient.SqlVisitor.VisitSource(SqlSource source)
     at System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitSelect(SqlSelect select)
     at System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
     at System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitAlias(SqlAlias a)
     at System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
     at System.Data.Linq.SqlClient.SqlVisitor.VisitSource(SqlSource source)
     at System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitSelect(SqlSelect select)
     at System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
     at System.Data.Linq.SqlClient.SqlVisitor.VisitSequence(SqlSelect sel)
     at System.Data.Linq.SqlClient.SqlVisitor.VisitExists(SqlSubSelect sqlExpr)
     at System.Data.Linq.SqlClient.SqlVisitor.VisitSubSelect(SqlSubSelect ss)
     at System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitSubSelect(SqlSubSelect ss)
     at System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
     at System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitExpression(SqlExpression expr)
     at System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitBinaryOperator(SqlBinary bo)
     at System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
     at System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitExpression(SqlExpression expr)
     at System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitSelect(SqlSelect select)
     at System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
  </code></pre>
  
  <p>What am I doing wrong? Google/Bing wont report many solutions to this, but it seems straight forward.</p>
  
  <p>This is not the solution -- it doesn't work. Same Error.</p>
  
  <p><a href="https://stackoverflow.com/questions/1084339/working-around-linqtosqls-queries-with-local-collections-are-not-supported-exce">Working around LinqToSQls &quot;queries with local collections are not supported&quot; exception</a></p>