title: Struggling to combine two NHibernate queries in which I intersect the results
body: <p>I've crafted two queries which both work fine, but I am really struggling to understand how to combine them. I think my biggest issue is the fact that I've used two different syntax for the queries, but I wasn't sure how to express my first query without using the "SQL-esque" mark-up.</p>
  
  <pre><code>List&lt;Task&gt; tasksFromQueue = NHibernateSession.CreateQuery(
      "Select t from Task t, QueueLocation q where q.Queue.ID = :queueID and (t.SiteID = q.ComponentID or t.OriginalSiteID = q.ComponentID)")
      .SetParameter("queueID", queueID).List&lt;Task&gt;().ToList();
  
  List&lt;Task&gt; tasksFromWorkflow = NHibernateSession
      .CreateCriteria(typeof(Task), "Task")
      .CreateCriteria("Task.Order", "Order")
      .CreateAlias("Task.TaskDevice", "TaskDevice").List&lt;Task&gt;();
  
  IEnumerable&lt;Task&gt; tasks = tasksFromWorkflow.Intersect(tasksFromQueue);
  </code></pre>
  
  <p>As you can see I have two issues:</p>
  
  <ul>
  <li>Using verbose syntax for the first query and the NHibernate mark-up for the second query.</li>
  <li>Hitting the DB twice and then intersecting the results.</li>
  </ul>
  
  <p>The tasksFromWorkflow query is actually a lot more complicated than seen above. If you'd like to see the whole query <a href="https://gist.github.com/0b29592051c85c5fb620" rel="nofollow noreferrer">click here.</a> I wasn't sure if the extra code really changed anything about my problem -- so I decided to keep the immediately displayed snippet as short as possible while still explaining the problem.</p>
  
  <p>I read that NHibernate <a href="https://stackoverflow.com/questions/3803325/nhibernate-intersection">doesn't support intersection</a>, so perhaps it isn't possible to achieve in one query without becoming extremely convoluted?</p>