gpt4 book ai didi

c# - 为什么使用 Linq Group By Sum 会出现转换错误?

转载 作者:行者123 更新时间:2023-11-30 21:27:40 56 4
gpt4 key购买 nike

我尝试使用 2 个查询来获得减法的结果,然后按总和进行分组。逻辑似乎不错,但我有以下错误:无法隐式转换类型 'System.Collection.Generic.List' <> 'to' int '

我的要求:

var postesList = (from od in db.tbl_607_order_details
join o in db.tbl_607_order on od.FK_ID_order equals o.ID
where o.order_number == contract
select new OrderWizardViewModel
{
idPoste = od.ID,
posteNumber = od.poste_number,
contractQ = od.order_quantity,
recievedQ = od.recieved_quantity,
lifeTime = od.gaz_lifetime,
stockMini = od.stock_mini,
shippingDelay = od.shipping_delays,
onTheRoadQ = 0
}).OrderBy(t => t.posteNumber).ToList();

foreach (var item in postesList)
{
item.onTheRoadQ = (from od in db.tbl_607_order_details
join srd in db.tbl_607_shipping_request_details on od.ID equals srd.FK_ID_order_details
where item.idPoste == srd.FK_ID_order_details & srd.shipping_quantity > srd.reception_quantity
select new
{
quantity = (srd.shipping_quantity - srd.reception_quantity.Value)
}).GroupBy(t => t.quantity).Select(x => new { Sum = x.Sum(y => y.quantity) }).ToList();
}

我想用 shipping_quantity - reception_quantity 的总和填充 postesList.onTheRoadQ

一些想法?

最佳答案

你所有的语句都返回一个列表,最后只是 Sum 来对列表的所有值求和。

item.onTheRoadQ = (from od in db.tbl_607_order_details
join srd in db.tbl_607_shipping_request_details on od.ID equals srd.FK_ID_order_details
where item.idPoste == srd.FK_ID_order_details & srd.shipping_quantity > srd.reception_quantity
select srd.shipping_quantity - srd.reception_quantity.Value
).Sum()

关于c# - 为什么使用 Linq Group By Sum 会出现转换错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57408124/

56 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com