1

私は以下の基準を持っています。

session.CreateCriteria<DomainModels.Models.FreieAbrechnung>()
       .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<DomainModels.Models.FreieAbrechnung>();

だから私はこのSqlステートメントを取得します:

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

問題は、制限 fp1_.IstAktiv = 1 が where 句にあることです。この制限は、左外部結合にある必要があります。このような:

left outer join FreieAbrechnungPosition fp1_ on this_.ID=fp1_.FreieAbrechnungID and fp1_.IstAktiv = 1

正しい Sql-Statement を取得するには、基準で何を変更する必要がありますか?

ありがとう、ダニ

4

1 に答える 1

0

結合に条件を追加するには、条件の代わりに HQL を使用する必要があります。

クエリの大まかな翻訳は次のようになります。

select f
from FreieAbrechnung f
left join f.FreieAbrechnungPositionen fp with IstAktiv = 1
where f.IsAktiv = 1
... etc
于 2010-11-14T16:45:39.497 に答える