无法将类型'System.Linq.IQueryable <double>'隐式转换为'double'</double>

时间:2015-04-18 20:18:19

标签: c# linq

我想收集所有具有相同商品编号的商品的价格 但是显示出这个问题 无法隐式转换类型System.Linq.IQueryable&#39;到&#39;加倍&#39;

我如何纠正这个?

下面是代码:

public double oIlstGetVouchersDetailjh(int nvoucherID)
        {
            Training_sNairoukhEntities1 sNairoukhEntities1 = new Training_sNairoukhEntities1();
            double olstInvoicesSrech = from Entity in sNairoukhEntities1.INV_InventoryItems
                                       where (Entity.ItemID == nvoucherID)
                                       group Entity by Entity.ItemID into g
                                       select g.Sum(s => s.ItemPrice);

            ret

1 个答案:

答案 0 :(得分:1)

您正在按ItemID进行过滤,然后进行分组。不需要在这里分组。直接选择总和:

double olstInvoicesSrech = (from Entity in sNairoukhEntities1.INV_InventoryItems
                            where Entity.ItemID == nvoucherID
                            select Entity.ItemPrice).Sum();

如果你想总结所有行并按ItemID对它们进行分组,那么:

var olstInvoicesSrech = from Entity in sNairoukhEntities1.INV_InventoryItems
                        group Entity by Entity.ItemID into g
                        select new { g.Key.ItemID, si =  g.Sum(s => s.ItemPrice) };