0
select T.Id, count(Th.ampount)
from TH, T
where Th.Tid= T.id
group by T.Id
如何使用流利的nhibernate寫上述查詢。我不想使用CreateSQLQuery()。聚合查詢流利的nhibernate
select T.Id, count(Th.ampount)
from TH, T
where Th.Tid= T.id
group by T.Id
如何使用流利的nhibernate寫上述查詢。我不想使用CreateSQLQuery()。聚合查詢流利的nhibernate
session.QueryOver<TH>()
.JoinAlias(th => th.Ts,() => tAlias)
.SelectList(list => list
.SelectGroup(th => th.Id)
.SelectCount(() => tAlias.amount)
// or did you mean
.SelectSum(() => tAlias.amount)
)
.List<object[]>();
Fluent NHibernate是一個映射工具,查詢機制可以是HQL,ICriteria,QueryOver或Query。你更傾向哪個? – Rippo
QueryOver或Icriteria – user1147738
在帖子中找到答案: http://stackoverflow.com/questions/10399448/nhibernate-aggregate-query-for-one-to-many-relation – user1147738