【问题标题】:How to Convert this Linq Query into Lambda Expression如何将此 Linq 查询转换为 Lambda 表达式
【发布时间】:2011-07-18 18:19:48
【问题描述】:
        foreach (lc_ShoppingCart sc in shQuery)
        {
            //Decrement the Product Table's Total Remaining row with the quantity
            var ProductInventoryQuery = (from pr in db.lc_ProductInventories
                                         join c in db.lc_ColorTables on pr.Color equals c.Color
                                         join s in db.lc_SizeTables on pr.Size equals s.Size
                                         where pr.ProductID == Convert.ToInt32(sc.ProductID)
                                         where pr.Color == c.Color
                                         where pr.Size == s.Size
                                         select pr).First();
            ProductInventoryQuery.Quantity = ProductInventoryQuery.Quantity - sc.Quantity;
        }

【问题讨论】:

标签: asp.net linq


【解决方案1】:

大概是这样的:

var ProductInventoryQuery = 
       db.lc_ProductInventories.Where(w => w.ProductID == Convert.ToInt32(sc.ProductID))
         .Join(db.lc_ColorTables, p => p.Color, ct => ct.Color, (p, ct) => new { ProdInv = p, ColorTables = ct })
         .Join(db.lc_SizeTables, p => p.Size, st => st.Color, (p, st) => new { ProdInv = p, SizeTables = st })
         .First();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多