簡體   English   中英

NHibernate加入和限制條件

[英]NHibernate Join and Restriction Criteria

我試圖編寫一個NHibernate標准,該標准可以有效地同時加入和限制。 我的數據庫看起來像這樣...

案例--->客戶產品<---客戶案例--->案例狀態

每個案例與一個客戶產品相關聯(許多案例與一個產品相關)。

每個客戶都有許多客戶產品(一個客戶有很多客戶產品)。

每個案例還具有一個案例狀態(很多案例中一個案例狀態)。

這已用XML文件映射,案例和客戶之間(通過客戶產品)的多對多分辨率已通過CustomerProduct映射中的Sets <>解決,這意味着CustomerProduct實體已設置:

顧客

案例

然后,我創建一個鍵入“案例”的條件。 我需要應用的標准是...。

  1. 狀態IN [各種狀態代碼]。 已經實現了...。

    條件.Add(Restrictions.In(“ CaseStatus.CaseStatusId”,狀態));

  2. 現在,我只需要為特定客戶ID選擇案例。 我努力了...

    條件.Add(“ CustomerProduct.Customer.CustomerId”,customerId);

這不起作用,NHibernate告訴我它無法解析到CustomerProduct.Customer.CustomerId的映射。

Case具有CustomerProduct對象的屬性。

CustomerProduct具有客戶對象的屬性。

客戶具有CustomerId的屬性。

任何想法為什么它行不通?

謝謝。

我認為您需要為CustomerProduct.Customer創建別名:

criteria.CreateAlias("CustomerProduct", "customerProduct");
criteria.CreateAlias("customerProduct.Customer", "customer");
criteria.Add(Restrictions.Eq("customer.CustomerId", customerId));

我很驚訝IN限制在沒有別名的情況下有效。 這是一篇有關使用Criteria API執行聯接查詢的好文章

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM