title: NHibernate Criteria API error with create alias and a collection of projections
body: <p>I'm tasked with generating a list of member data using the NHibernate Criteria API. I need to incorporate paging and filtering based on checkboxes in the UI. What makes this a bit more complex is that I'm not just fetching data from one entity, but this entity has a <code>HasMany</code> relationship to other entities.</p>
  
  <p>I currently have an error: </p>
  
  <pre><code>Error executing multi Criteria: 
  [SELECT DISTINCT TOP 1000 this_MemberID as y0_ 
   FROM _Members
   Left Outer Join _SubMemberTerms ON _SubMemberTerms.MemberID = this_.MemberID
   Left Outer Join _MemberTerms ON _MemberTerms.MemberID = this_.MemberID
   Left Outer Join _ScriptOption ON _ScriptOption.ID = _MemberTerms.ScriptOpID
   WHERE _MagazineID = 100
   AND 
      (_ScriptOption.MagID IN (1234,5678,9101,.....) 
          OR _ScriptOption.MemberID IS NULL
          OR _ScriptOption.Active = 0)
   AND
      (_SubMemberTerms._ScriptOpID IN (1234,5678,9101,.....)
          OR _SubMemberTerms.ID IS NULL);]
  </code></pre>
  
  <blockquote>
    <p>The Inner exception is:  The value \"5554302\" is not of type
    \"MyBusiness.MemberInfo\" and cannot be used in this generic
    collection. Parameter name: value.</p>
  </blockquote>
  
  <p>Right now I'm just looking at the Member's ID because I commented every other projection in my projection list out. Otherwise the error would've stated "The Value \"System.object[]\"...</p>
  
  <p>My Criteria Code:</p>
  
  <pre><code>var filteredList = CurrentSession.CreateCriteria&lt;MemberInfo&gt;("this_")
                     .SetProjection(Projections.Distinct(Projections.ProjectionList()
                     .Add(Projections.Alias(Projections.Property("ManagedMemberID"), "MemberID"))))
                     .Add(Restrictions.Eq("_MagazineID", (int)magID))
                     .CreateAlias("MemTermsList", "_MemberTerms", NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                     .CreateAlias("_MemberTerms.ScriptOpInfo", "_ScriptOption", NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                     .CreateAlias("SubTermsList", "_SubMemberTerms", NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                     .SetFirstResult(startposition)
                     .SetMaxResults(1000);
  </code></pre>
  
  <p>I also have a <code>Criteria</code> made for getting the count of the total query and not just the 1k returned. It's the same as the <code>Criteria</code> I made for <code>filteredList</code>.</p>
  
  <pre><code>//code for how I'm adding in the MagID's and ScriptOpId's
  Disjunction magDisjunction = new Disjunction();
  Disjunction subTermsDijunction = new Disjunction();
  if(TheCheckBoxThatAppliesIsChecked)
  {
      magDisjunction.Add(Restrictions.In("_ScriptOption.MagID", (List&lt;int&gt;)selectedMags))
                    .Add(Restrictions.IsNull("_MemberTerms.MemberID"))
                    .Add(Restrictions.Eq("_MemberTerms.Active", false));
  
      filteredList.Add(magDisjunction);
  }
  if(TheOtherCheckBoxThatAppliesIsChecked)
  {
      subTermsDisjunction.Add(Restrictions.In("_SubMemberTerms.SciptOpID", (List&lt;int&gt;)selectedScriptOp))
                    .Add(Restrictions.IsNull("_SubMemberTerms.SubMemberTermsID"));
  
      filteredList.Add(subTermsDisjunction);
  }
  
  var finishedList = filteredList.Future&lt;MemberInfo&gt;().ToList&lt;MemberInfo&gt;();
  var count = listCount.FutureValue&lt;int&gt;().Value;
  </code></pre>
  
  <p>EDIT:
  I had a typo in my projections.Alias, switched form "MemberID", to "ManagedMemberID".</p>