NHibernate QueryOver 对集合中字段的值求和
我有一个包含子集合的父对象:
class Parent {
int Id {get;set;}
....
IList<Child> Children {get;set;}
}
class Child {
int Id {get;set;}
int Value {get;set;}
...
Parent Parent {get;set;}
}
FluentNHibernate 的映射是
ParentMap:
Id(x => x.Id, "id").GeneratedBy.Assigned();
...
HasMany<Child>(x => x.Children).AsBag().KeyColumn("parentid").Inverse()
.Fetch.Join().Cascade.AllDeleteOrphan();
ChildMap:
Id(x => x.Id).GeneratedBy.Assigned();
....
Map(x => x.Value, "value");
References<Parent>(x => x.Parent, "parentid").NotFound.Ignore();
我必须像这样映射 NHibernate 的 SQL 查询:
select p.id, sum(c.value)
from parent p, child c
where p.id = c.parentid
是否可以通过 QueryOver 转换此查询?
谢谢
I have a parent object containing a collection of children:
class Parent {
int Id {get;set;}
....
IList<Child> Children {get;set;}
}
class Child {
int Id {get;set;}
int Value {get;set;}
...
Parent Parent {get;set;}
}
The mapping whith FluentNHibernate is
ParentMap:
Id(x => x.Id, "id").GeneratedBy.Assigned();
...
HasMany<Child>(x => x.Children).AsBag().KeyColumn("parentid").Inverse()
.Fetch.Join().Cascade.AllDeleteOrphan();
ChildMap:
Id(x => x.Id).GeneratedBy.Assigned();
....
Map(x => x.Value, "value");
References<Parent>(x => x.Parent, "parentid").NotFound.Ignore();
I have to map whith NHibernate a SQL query like this:
select p.id, sum(c.value)
from parent p, child c
where p.id = c.parentid
Is it possible to translate this query whith QueryOver?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以试试这个
或者这个
或者这个吗
can you try this
or this
or this