C# Linq-nhibernate群与连接

C# Linq-nhibernate群与连接,c#,linq,nhibernate,group-by,C#,Linq,Nhibernate,Group By,考虑一个简单的订单示例(应获得每个产品的标题和订购数量): (注意:按标题分组不是一个好答案) var orderQuery= session.Query() 其中(ol=>ol.Quantity>0) .GroupBy(ol=>ol.Product.Id) .选择(x=>new { productId=x.Key, 数量=x.总和(i=>i.数量) }); 变量查询= session.Query() .Join(orderQuery, x=>x.Id, x=>x.productId, (x,

考虑一个简单的订单示例(应获得每个产品的标题和订购数量): (注意:按标题分组不是一个好答案)

var orderQuery=
session.Query()
其中(ol=>ol.Quantity>0)
.GroupBy(ol=>ol.Product.Id)
.选择(x=>new
{ 
productId=x.Key,
数量=x.总和(i=>i.数量)
});
变量查询=
session.Query()
.Join(orderQuery,
x=>x.Id,
x=>x.productId,
(x,p)=>新的{x.FeedItem.Title,p.quantity});
然而,这带来了一个巨大的挑战

无法解析属性:键:订单行


有什么想法吗?

尝试使用查询和投影创建查询

映射很难说,您的OrderLine实体似乎没有名为Key的属性
.Select(x=>new{productId=x.Key…
哪个NHibernate版本?版本2.1 LINQ提供程序有一些问题。
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 });