NHibernate 查询具有至少一个子对象的父对象的标准?
在我的项目中,Lines
可以分组,Group
的类型可以是 Crossing
(1) 或 Parallel (2).我需要找到至少具有一组指定类型的所有行(在本例中为 1)。给定行的 Id 可以位于组的列
LineA
或 LineB
上。这是我到目前为止所得到的:
Criteria crit = session.CreateCriteria(typeof(Line), "ln");
DetachedCriteria count = DetachedCriteria.For<Group>()
.SetProjection(Projections.CountDistinct("Id"))
.Add(Expression.Or(
Expression.EqProperty("LineA", "ln.Id"),
Expression.EqProperty("LineB", "ln.Id")))
.Add(Expression.Eq("GroupTypeId", 1));
crit.Add(Subqueries.Gt(0, count));
In my project, Lines
can be grouped and a Group
has a type which can be either Crossing
(1) or Parallel
(2). I need to find all lines which has at least one group of a specified type (in this case, 1). The Id of a given line can be either on column LineA
or LineB
of a group. Here is where i got so far:
Criteria crit = session.CreateCriteria(typeof(Line), "ln");
DetachedCriteria count = DetachedCriteria.For<Group>()
.SetProjection(Projections.CountDistinct("Id"))
.Add(Expression.Or(
Expression.EqProperty("LineA", "ln.Id"),
Expression.EqProperty("LineB", "ln.Id")))
.Add(Expression.Eq("GroupTypeId", 1));
crit.Add(Subqueries.Gt(0, count));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我成功了!
{alias}
是正在查询的对象的占位符。I got it working!
{alias}
is a placeholder for the object being queried.