title: nHibernate bag query issue
body: <p>I have the following scenario in nHibernate: </p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;class name="TestApp.Components.User,TestApp.Components"  table="Users"&gt;
      &lt;id name="Id" column="UserId" type="Int32" unsaved-value="0"&gt;
        &lt;generator class="native"&gt;&lt;/generator&gt;
      &lt;/id&gt;
      &lt;property name="UserName" type="string" length="100" not-null="false"/&gt;
      &lt;bag name="Groups" table="User_Group" lazy="true" &gt;
        &lt;key column="UserId"&gt;&lt;/key&gt;
        &lt;many-to-many class="Group" column="GroupId" /&gt;
      &lt;/bag&gt;  
  &lt;class&gt;
  </code></pre>
  
  <p>I need to be able to write an query to return all the users that are in a collection of groups.</p>
  
  <p>Essentially I want the following sql to execute:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT DISTINCT username from users u, user_group ug  
  WHERE u.userid = ug.userid  
  AND (ug.groupid = 1 OR ug.groupid = 2 OR ug.groupid = 3)
  </code></pre>
  
  <p>I know I can do this in HQL, but I want to do it using the ICriteria interface.</p>
  
  <pre class="lang-cs prettyprint-override"><code>var session = sessionManager.GetSession();  
  var items = session.CreateCriteria(typeof(User));  
  
  ICriterion criterion = null;  
  
  foreach (var groupid in Groups)  
  {  
      ICriterion tempCriterion = Restrictions.Eq("Groups.GroupId", groupid);  
      criterion = criterion == null ? tempCriterion : Restrictions.Or(criterion, tempCriterion);  
  }  
  items.Add(criterion);
  </code></pre>
  
  <p>I've tried the above but it errors, and I can't seem to figure out what I am missing. in the query.</p>
  
  <p>Can someone point me in the right direction with regards to how I need to structure this query?</p>