[英]NH 3.0 GA Linq Group By not working
NH 3.0 GA是否仍不支持LINQ group by
,或者我做錯了什么? 我的LINQ是:
var q = from p in session.Query<Product>()
group p by p.Category into g
select new {
Category = g.Key,
TotalValue = g.Sum(p => p.UnitsInStock * p.Price)
};
Witch轉換為以下SQL:
select category1_.Id as col_0_0_,
cast(sum(product0_.UnitsInStock*product0_.Price) as DOUBLE PRECISION) as col_1_0_,
category1_.Id as Id0_,
category1_.Name as Name0_
from [Product] product0_
left outer join [Category] category1_ on product0_.Category_id=category1_.Id
group by category1_.Id
由於category1_.Name不在group by子句中,因此會生成SqlException。
這是一個已知的錯誤 ? 有解決方法嗎? 該LINQ在EF 4中運行良好。
NHibernate的group by
不夠聰明,無法在按實際分組時添加實體的所有屬性。
另一種方法是僅在選擇列表中使用Id,然后在Linq-to-objects中使用session.Load
來投影Category實體。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.