title: Complex querying with NHibernate
body: <p>I have this problem: 
  When I try to implement Ayende's complex searching found at: 
  <a href="http://ayende.com/Blog/archive/2006/12/07/ComplexSearchingQueryingWithNHibernate.aspx" rel="noreferrer">http://ayende.com/Blog/archive/2006/12/07/ComplexSearchingQueryingWithNHibernate.aspx</a> 
  with the object graph: 
  Person: 
             M:1 Address: 
                                M:1 Street: 
                                                M:1 Place: 
                                                                M:1 
  Country 
  I get the following error: NHibernate.QueryException: Cannot use 
  subqueries on a criteria without a projection. 
  I am doing this: </p>
  
  <pre><code>public List&lt;Person&gt; Find() 
  { 
      DetachedCriteria query = DetachedCriteria.For&lt;Person&gt;(); 
      AddAddressQuery(query); 
      return personRepository.Find(query);
  } 
  
  private void AddAddressQuery(DetachedCriteria query) 
  { 
       DetachedCriteria addressQuery = null; 
       if (!String.IsNullOrEmpty(SearchParams.HouseNumer)) 
       { 
           addresaQuery = DetachedCriteria.For&lt;Address&gt;(); 
           addresaQuery.Add(Restrictions.Eq("HouseNumer", 
  SearchParams.HouseNumer)); 
       } 
       this.AddStreetQuery(ref addressQuery); 
       if (addressQuery != null) 
       { 
           query.CreateCriteria("Address1", 
  "address1").Add(Subqueries.Exists(addressQuery)); 
       } 
  } 
  
  private void AddStreetQuery(ref DetachedCriteria query) 
  { 
      DetachedCriteria streetQuery = null; 
      if (this.SearchParams.StreetId.HasValue) 
      { 
          streetQuery = DetachedCriteria.For&lt;Street&gt;(); 
          streetQuery .Add( Restrictions.Eq("Id", 
  this.SearchParams.StreetId.Value)); 
      } 
      if (streetQuery != null) 
      { 
          query = query ?? Query.CreateCriteria("Address1"); 
          query.CreateCriteria("Street", 
  "street").Add(Subqueries.Exists(streetQuery )); 
      } 
  } 
  </code></pre>
  
  <p>What Am I doing wrong? 
  Please help </p>