Linq nhibernate 分组和加入
考虑一个简单的订单示例(应该获取每个产品的标题和订购数量): (注意 - 按标题分组不是一个好的答案)
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 });
但是,这会引发
无法解析属性:Key of:OrderLine
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 QueryOver 和 Projections 创建查询
示例
Try to create your query using QueryOver and Projections
Sample