说我有一个这样的实体
public class Something
{
public int Id{get;set;}
public string Name{get;set;}
public IList<SomeOther> Assosiation{get;set}
}
Run Code Online (Sandbox Code Playgroud)
我如何使用 nhibernate 查询以使用 Criteria API 获取具有超过 10 个关联的所有东西实体?
干杯科林
像这样的东西:
var dc = DetachedCriteria.For<SomeOther>()
.SetProjection(Projections.GroupProperty("Something.Id"))
.Add(Restrictions.Gt(Projections.RowCount(), 10));
var criteria = session.CreateCriteria(typeof (Something))
.Add(Subqueries.PropertyIn("Id", dc));
Run Code Online (Sandbox Code Playgroud)
这会产生这样的东西:
SELECT this_.Id as Id7_0_,
this_.Title as Title7_0_
FROM Something this_
WHERE this_.Id in (SELECT this_0_.SomethingId as y0_
FROM SomeOther this_0_
GROUP BY this_0_.SomethingId
HAVING count(* ) > 10 /* @p0 */)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
546 次 |
| 最近记录: |