如何在LInq中检索Total [英] How to retrive Total in LInq
问题描述
var j =从订单中的o
在订单上加入OT.OrderId等于OT.OrderId
将OT.ProductId组合o.OrderId加入g
选择新的{OrderId = g.Key,ProductId = g};
类Orders包含TotalPrice。我想要检索它,但是我收到了错误,
我试过这样的
var j =来自订单中的o
在订单详情中加入OT on o.OrderId等于OT.OrderId
group OT.ProductId by o.OrderId into g
select new {OrderId = g.Key,ProductId = g,TotalPrice = o .TotalPrice};
显示o这个词不存在的错误,请帮助
< blockquote>您好b $ b
我不确定您是否需要每个订单的总价格,或者您是否想要所有订单的总和。
如果你想要每行的TotalPrice你应该需要的是:
var results =(来自我在你的收藏中
g。由i.Column组成g
选择新的
{
ColumnName = o.Column,
ColumnTotal = o.Column,
})。ToList();
Els如果你想要所有订单的总和,请尝试:
var results =(来自我在你的收藏中
group g by i.Column into g
选择新的
{
ColumnName = i.Column,
ColumnTotal = i.Sum(x = > x.Value)
})。ToList();
让我知道你是怎么过的。
>
var j=from o in Orders
join OT in OrderDetails on o.OrderId equals OT.OrderId
group OT.ProductId by o.OrderId into g
select new{OrderId=g.Key,ProductId=g};
The class Orders Contains TotalPrice. I want to retrieve it, but i get error,
I tried like this
var j=from o in Orders
join OT in OrderDetails on o.OrderId equals OT.OrderId
group OT.ProductId by o.OrderId into g
select new{OrderId=g.Key,ProductId=g,TotalPrice=o.TotalPrice};
It shows an error the term 'o' does not exist, pls help
Hi
I am not sure if you want the total price for each order or if you want the sum of all the orders.
If you want the TotalPrice per row all you should need is:
var results = (from i in yourCollection
group g by i.Column into g
select new
{
ColumnName = o.Column,
ColumnTotal = o.Column,
}).ToList();
Else if you want the sum of all orders try:
var results = (from i in yourCollection
group g by i.Column into g
select new
{
ColumnName = i.Column,
ColumnTotal = i.Sum(x => x.Value)
}).ToList();
Let me know how you get on.
这篇关于如何在LInq中检索Total的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!