我尝试使用2个查询来获得减法的结果,然后按总和进行分组。逻辑看似不错,但出现以下错误:无法将类型'System.Collection.Generic.List''隐式转换为'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的总和来填充postesList.onTheRoadQ-有想法吗 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 您的所有语句都返回一个列表,最后只需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() (adsbygoogle = window.adsbygoogle || []).push({}); 10-06 12:07