title: Nhibernate Criteria retrieve child of parent with restriction on other child of parent
body: <p>I need to be able to write the following query as a Criteria.</p>
  
  <pre><code>SELECT hist.*
  FROM
      Administration admin
      INNER JOIN Item item ON item.AdministrationId = admin.AdministrationId
      INNER JOIN ItemHistory hist ON hist.ItemId = item.ItemId
  WHERE
      item.itemId = @param
      and hist.IsError =
          (
              SELECT (CASE status.errorType
                          WHEN 'Warning' THEN 0
                          ELSE 1
                      END
                     )
              FROM
                  AdminStatus status
              WHERE
                  status.AdministrationId = admin.AdministrationId
                  AND status.Group = 'Issues'
          )
  </code></pre>
  
  <p>I'm pretty sure I'll need to do the sub query as a detached criteria:</p>
  
  <pre><code>var status = DetachedCriteria.For&lt;AdminStatus&gt;("status");
          status.CreateAlias("status.Administration", "admin");
          status.Add(Restrictions.Eq("status.Group", "Issues"));
          status.SetProjection(Projections.Property("AdministrationId"));
          status.SetProjection(Projections.Conditional(
                          Restrictions.Eq("status.errorType", "Warning"),
                          Projections.Constant(0),
                          Projections.Constant(1)));
  </code></pre>
  
  <p>But I'm not sure how to join that with my primary criteria:</p>
  
  <pre><code>    var criteria = Session.CreateCriteria&lt;ItemHIstory&gt;("hist");
          criteria.CreateAlias("ItemHistory.Item", "item");
          criteria.CreateAlias("item.Administration", "admin");    
  </code></pre>