繁体   English   中英

NHibernate中的IN()语句如何工作? (使用条件)

[英]How do IN () statements work in NHibernate? (Using Criteria)

我正在尝试使用NHibernate创建以下内容。 我已经使用fluent完成了所有映射,我可以很好地进行基本查询,但是我不知道该怎么做。

-**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)

切记,对于该帖子,Product表已被简化了很多,我更喜欢使用IN语句来简化其余查询。 理想情况下,我想使用Criteria创建查询,因为我将使用Criteria来分页结果。

提前致谢

当联接足够时,为什么要使用in呢? 如果您的Products类具有映射的主题集合,那么您可以使用此条件

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM