2008-12-30 94 views
2

我想創建使用NHibernate的下面的等效。我已經完成了所有映射使用流利,我可以做基本查詢就好,但我不知道如何做到這一點。IN()語句在NHibernate中如何工作? (使用標準)

-**Product Table** 
Reference 
Title 
Subjects (Many to Many relationship) 
Price 

-**Subject table** 
SubjectID 
Name 

-**SubjectToProductMapping Table** 
Reference 
SubjectID 

現在我需要做的是:

SELECT * 
FROM Product 
WHERE Reference IN 
    (Select Reference FROM SubjectToProductMapping WHERE SubjectID = @SubjectID) 

霸菱考慮到產品表已經簡化了很多的職位,而我寧願使用IN語句來保持休息的查詢更簡單。我希望使用Criteria創建查詢,因爲我將使用Criteria來分頁結果。

在此先感謝

回答

0

爲什麼要在連接足夠時使用in?只要您的產品類有題材映射的集合,那麼你可以只使用這個標準

IList<Product> results = session.CreateCriteria(typeof(Product)) 
           .CreateCriteria("Subjects", JoinType.Join) 
           .Add(Resitctions.Eq(Projections.ID, subjectID)) 
           .List<Product>(); 
相關問題