title: How do I do a "contains" query with f# query expressions?
body: <p>How do I do a query expression similar to a SQL IN-query?</p>
  
  <p>I'm trying to do something along these lines:</p>
  
  <pre><code>let customerNumbers = set ["12345"; "23456"; "3456"]
  let customerQuery = query {
      for c in dataContext.Customers do
      where(customerNumbers.Contains(c.CustomerNumber))
      select c
  }
  </code></pre>
  
  <p>But I'm getting an error:</p>
  
  <pre><code>System.NotSupportedException: Method 'Boolean Contains(System.String)' has no supported translation to SQL.
  </code></pre>
  
  <p>Looking at the documentation for query expressions at <a href="http://msdn.microsoft.com/en-us/library/hh225374.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/hh225374.aspx</a> I should use another query for the contains part but this code doesn't work, the example is broken:</p>
  
  <pre><code>// Select students where studentID is one of a given list.
  let idQuery = query { for id in [1; 2; 5; 10] do select id }
  query { 
      for student in db.Student do
      where (idQuery.Contains(student.StudentID))
      select student
  }
  </code></pre>
  
  <p>idQuery does in fact not contain any "Contains" method.</p>
  
  <p>I have also tried:</p>
  
  <pre><code>let customerNumbers = set ["12345"; "23456"; "3456"]
  let customerQuery = query { 
      for c in dataContext.Customers do
      where (query { for x in customerNumbers do exists (c.CustomerNumber=x)})
      select r
  }
  </code></pre>
  
  <p>But this gives this error message:</p>
  
  <pre><code>System.NotSupportedException: Local sequence cannot be used in LINQ to SQL implementations of query operators except the Contains operator
  </code></pre>
  
  <p>I noticed after some more testing that the following also works fine in addition to Gene's suggestion:</p>
  
  <pre><code>let customerNumbers = set ["12345"; "23456"; "3456"]
  query {
      for customer in dataContext.Customer do
      where (query { for x in customerNumbers do contains customer.CustomerNumber})
      select customer
  }
  </code></pre>