【发布时间】:2011-07-20 22:15:39
【问题描述】:
考虑一个简单的订单示例(应该获取每个产品的标题和订购数量): (注意 - 按标题分组不是一个好的答案)
var orderQuery =
session.Query<OrderLine>()
.Where(ol => ol.Quantity > 0)
.GroupBy(ol => ol.Product.Id)
.Select(x => new
{
productId = x.Key,
quantity = x.Sum(i => i.Quantity)
});
var query =
session.Query<Product>()
.Join(orderQuery,
x => x.Id,
x => x.productId,
(x, p) => new { x.FeedItem.Title, p.quantity });
但是,这会引发
无法解析属性:OrderLine 的键
有什么想法吗?
【问题讨论】:
-
很难用您的映射来判断,您的 OrderLine 实体似乎没有名为 Key 的属性?
.Select(x => new { productId = x.Key... -
哪个 NHibernate 版本? 2.1 版 LINQ 提供程序存在一些问题。
标签: c# linq nhibernate group-by