2015-10-16 64 views
0

我正在從一個轉換項目.net 2.0到.net 4.5.1,並且遇到了與NHibernate HQL有關的問題。我的問題是在運行時添加一個子查詢,該查詢存儲在數據庫中用於過濾目的,並在查詢被NH轉換之前附加到HQL。子查詢中的兩個左連接被刪除。nhibernate正在刪除加入子查詢

翻譯之前的查詢:

Select allergy From Allergy allergy left join allergy.HealthcareWorker healthcareWorker where (1=1) and healthcareWorker.Id = :healthcareWorkerId and ((
allergy.Id in (Select allergy.id From Allergy allergy 
    left join allergy.HealthcareWorker healthcareWorker 
    left join healthcareWorker.LatticeFacility latticeFacility 
    Where latticeFacility.Id in (134,342)))) 

變換後:

select allergy0_.AllergyID as AllergyID41_, allergy0_.RowVersionNumber as RowVersi2_41_, allergy0_.AllergyDate as AllergyD3_41_, allergy0_.Comments as Comments41_, allergy0_.InactivationDate as Inactiva5_41_, allergy0_.CreatedAt as CreatedAt41_, allergy0_.CreatedBy as CreatedBy41_, allergy0_.LastModAt as LastModAt41_, allergy0_.LastModBy as LastModBy41_, allergy0_.HealthcareWorkerID as Healthc10_41_, allergy0_.AllergyTypeID as Allergy11_41_, allergy0_.AllergySubstanceID as Allergy12_41_, allergy0_.MedicationItemID as Medicat13_41_, allergy0_.MedicalPractitionerConfirmedID as Medical14_41_, allergy0_.InactivationReasonID as Inactiv15_41_, case when allergy0_.InactivationDate is not null then case when allergy0_.InactivationReasonID is not null then 0 else 1 end else 1 end as formula4_ from tblAllergy allergy0_ left outer join tblHealthcareWorker healthcare1_ on allergy0_.HealthcareWorkerID=healthcare1_.HealthcareWorkerID where 1=1 and [email protected] and (allergy0_.AllergyID in (select allergy2_.AllergyID from tblAllergy allergy2_ where latticefac4_.LatticeFacilityID in (134,342)) 

這產生一個異常的多部分標識符 「latticefac4_.LatticeFacilityID」 不能被約束。很明顯,因爲連接已經從子查詢中刪除。

我是NHibernate的新手,所以不勝感激。

感謝

回答

0

所以這結束了與NHibernate無法識別表的別名的問題。原來,連接的子查詢別名需要從外部查詢別名中唯一。