title: SQL IN statement in Linq for NHibernate
body: <p>I have this Lookup to group ResultId by Symbol.
  I have Linq query below but I cannot make SQL IN statement by using Contain() which is state by this post <a href="http://blog.wekeroad.com/2008/02/27/creating-in-queries-with-linq-to-sql" rel="nofollow">http://blog.wekeroad.com/2008/02/27/creating-in-queries-with-linq-to-sql</a></p>
  
  <pre><code>        // This will group ResultIds (Guid) by their symbol (string).
          var asd = ResultIdsAndSymbols.ToLookup(x =&gt; x.Symbol, y =&gt; y.ResultID);
  
          foreach (var qwe in asd)
          {
              var Numbers = (from t in Session.Query&lt;TableName&gt;()
                           where qwe.Contains(t.ResultID)
                           select t.Number).ToList();
          }
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>After retrying this code and deep analyzing the error (System.InvalidCastException: Object must implement IConvertible), I got this informative error message: <em>"Failed to convert parameter value from a Grouping to a Guid"</em>. <code>qwe</code> is a type of <code>IGrouping&lt;string, Guid&gt;</code> and it will become <code>IEnumerable&lt;Guid&gt;</code> which should not be a problem like we pass this into a <code>List</code> constructor or used in <code>foreach</code> statement. The exception thrown in <code>System.Data.SqlClient</code>. I think NHibernate simply pass the <code>Grouping&lt;TKey, TElement&gt;</code> into the sql parameter that cause the error. NHibernate should be designed to enumerate to any <code>IEnumerable&lt;T&gt;</code> and generate the SQL IN query just like how it does for <code>List&lt;T&gt;</code>.</p>
  
  <p>The <code>List&lt;T&gt;</code>, Array[], <code>Stack</code> work well. So I change the code to this:</p>
  
  <pre><code>where qwe.ToList().Contains(t.ResultID)
  </code></pre>
  
  <p><strong>Update:</strong>
  Issue reported: <a href="https://nhibernate.jira.com/browse/NH-2762" rel="nofollow">https://nhibernate.jira.com/browse/NH-2762</a></p>