小编典典

linq案例陈述

c#

我需要有关linq(C#)中CASE语句的一些帮助:

osc_products.products_quantity =
      CASE 
         WHEN itempromoflag <> 'N' THEN 100000
         WHEN itemcat1 IN ('1','2','31') AND itemsalestatus = 'S' THEN 100000
         WHEN itemsalestatus = 'O' THEN 0
         ELSE cds_oeinvitem.itemqtyonhand - cds_oeinvitem.itemqtycommitted 
      END

我开始转换为linq,(我仍在学习):

cdsDBDataContext db = new cdsDBDataContext();
  var query = from items in db.cdsItems
              where items.ItemHandHeldFlag.Equals("Y") &&
              items.ItemQtyOnHand -  items.ItemQtyCommitted > 0
  select items;

此查询将库存状态从生产更新为贸易站点。


阅读 330

收藏
2020-05-19

共1个答案

小编典典

如果它只是 LINQ中*CASE 语句,请阅读(您的评论),然后再举一个例子。 *

Int32[] numbers = new Int32[] { 1, 2, 1, 3, 1, 5, 3, 1 };

var numberText =
(
    from n in numbers
    where n > 0
    select new
    {
        Number = n,
        Text = 
        (
            n == 1 ? "One" :
            n == 2 ? "Two" :
            n == 3 ? "Three" : "Unknown"
        )
    }
);
2020-05-19