title: NHibernate Left Join Restriction
body: <p>I have the following criteria.</p>
  
  <pre><code>session.CreateCriteria&lt;DomainModels.Models.FreieAbrechnung&gt;()
         .CreateAlias("FreieAbrechnungPositionen", "fp", JoinType.LeftOuterJoin)                                            
         .Add(Restrictions.Eq("fp.IstAktiv", true))
         .Add(Restrictions.Eq("Kunde.ID", kundenId))
         .Add(Restrictions.Eq("IstAktiv", true))
         .Add(Restrictions.Eq("Abgeschlossen", false))
         .SetResultTransformer(CriteriaSpecification.DistinctRootEntity)                                            
         .List&lt;DomainModels.Models.FreieAbrechnung&gt;();
  </code></pre>
  
  <p>So I get this Sql-Statement:</p>
  
  <pre><code>SELECT this_.ID as ID13_1_, this_.Version as Version13_1_, 
  this_.KundeID as KundeID13_1_, this_.Erstellungsdatum as Erstellu4_13_1_, 
  this_.Druckdatum as Druckdatum13_1_, this_.Abgeschlossen as Abgeschl6_13_1_, 
  this_.AbgeschlossenDatum as Abgeschl7_13_1_, this_.IstAktiv as IstAktiv13_1_, 
  this_.ErstelltDurchID as Erstellt9_13_1_, this_.ErstelltAm as ErstelltAm13_1_, 
  this_.MutationDurch as Mutatio11_13_1_, this_.MutationAm as MutationAm13_1_, 
  fp1_.FreieAbrechnungID as FreieAbr3_3_, fp1_.ID as ID3_, fp1_.ID as ID12_0_, 
  fp1_.Version as Version12_0_, fp1_.FreieAbrechnungID as FreieAbr3_12_0_, 
  fp1_.KundeID as KundeID12_0_, fp1_.Bezeichnung as Bezeichn5_12_0_, 
  fp1_.Betrag as Betrag12_0_, fp1_.Erstellungsdatum as Erstellu7_12_0_, 
  fp1_.MwStSteuerCodeID as MwStSteu8_12_0_, fp1_.IstAktiv as IstAktiv12_0_, 
  fp1_.ErstelltDurchID as Erstell10_12_0_, fp1_.ErstelltAm as ErstelltAm12_0_, 
  fp1_.MutationDurch as Mutatio12_12_0_, fp1_.MutationAm as MutationAm12_0_ 
  FROM 
  FreieAbrechnung this_ 
  left outer join FreieAbrechnungPosition fp1_ on this_.ID=fp1_.FreieAbrechnungID 
  WHERE 
  fp1_.IstAktiv = 1 and this_.KundeID = 1 and this_.IstAktiv = 1 and this_.Abgeschlossen = 0
  </code></pre>
  
  <p>The problem is, that the restrictions fp1_.IstAktiv = 1 is in the where clause. This restrictions have to be in the left outer join. Like this:</p>
  
  <pre><code>left outer join FreieAbrechnungPosition fp1_ on this_.ID=fp1_.FreieAbrechnungID and fp1_.IstAktiv = 1
  </code></pre>
  
  <p>What should I change in the criteria, that I get the right Sql-Statement?</p>
  
  <p>Thanks,
  Dani</p>