开发者

Linq nhibernate groups and joins

开发者 https://www.devze.com 2023-02-18 21:51 出处:网络
Consider a simple order example (should get the title and quantity ordered for each product): (note - grouping by Title is not a good answer)

Consider a simple order example (should get the title and quantity ordered for each product): (note - grouping by Title is not a good answer)

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 });

However, this throws a

could not resolve property: Key of: OrderLine

any ideas?


Try to create your query using QueryOver and Projections Sample

0

精彩评论

暂无评论...
验证码 换一张
取 消