C# IN()语句在NHibernate中如何工作?(使用标准)
我正在尝试使用NHibernate创建下面的等价物。我已经使用fluent完成了所有映射,我可以很好地完成基本查询,但我不知道如何做到这一点C# IN()语句在NHibernate中如何工作?(使用标准),c#,.net,nhibernate,criteria,C#,.net,Nhibernate,Criteria,我正在尝试使用NHibernate创建下面的等价物。我已经使用fluent完成了所有映射,我可以很好地完成基本查询,但我不知道如何做到这一点 -**Product Table** Reference Title Subjects (Many to Many relationship) Price -**Subject table** SubjectID Name -**SubjectToProductMapping Table** Reference SubjectID 现在我需要这样做:
-**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语句来简化查询的其余部分。理想情况下,我希望使用条件创建查询,因为我将使用条件来分页结果
提前感谢既然加入就足够了,为什么还要使用in?如果你的产品类有一个主题的映射集合,那么你可以使用这个标准
IList<Product> results = session.CreateCriteria(typeof(Product))
.CreateCriteria("Subjects", JoinType.Join)
.Add(Resitctions.Eq(Projections.ID, subjectID))
.List<Product>();
IList results=session.CreateCriteria(产品类型))
.CreateCriteria(“主题”,JoinType.Join)
.Add(Resitctions.Eq(Projections.ID,subject))
.List();
既然加入就足够了,为什么还要使用in?如果你的产品类有一个主题的映射集合,那么你可以使用这个标准
IList<Product> results = session.CreateCriteria(typeof(Product))
.CreateCriteria("Subjects", JoinType.Join)
.Add(Resitctions.Eq(Projections.ID, subjectID))
.List<Product>();
IList results=session.CreateCriteria(产品类型))
.CreateCriteria(“主题”,JoinType.Join)
.Add(Resitctions.Eq(Projections.ID,subject))
.List();