我尝试在LINQ中使用函数SUM,但不适用于子文档。 有没有人尝试使用SUM作为子文档?
我的示例查询:
var collection = database.GetCollection<Order>("Order").AsQueryable();
var query = from o in collection
from p in o.OrderItems
select p;
var query2 = from orderItem in query
group orderItem by orderItem.ProductId into g
select new
{
ProductId = g.Key,
TotalAmount = g.Sum(x=>x.UnitPriceExclTax)
};
TotalAmount,始终返回值0。
谢谢,
答案 0 :(得分:0)
Mongo c#LINQ驱动程序不能正确支持SUM。 https://jira.mongodb.org/browse/CSHARP-592
使用MongoQuery和汇总和更好。有关详细用法和示例,请参阅链接。 https://docs.mongodb.org/manual/reference/operator/aggregation/sum/