linq case 语句 [英] linq case statement

查看:33
本文介绍了linq case 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

osc_products.products_quantity =案件WHEN itempromoflag <>'N' THEN 100000WHEN itemcat1 IN ('1','2','31') AND itemsalestatus = 'S' THEN 100000WHEN itemsalestatus = 'O' THEN 0其他 cds_oeinvitem.itemqtyonhand - cds_oeinvitem.itemqtycommitted结尾

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

<块引用>

cdsDBDataContext db = new cdsDBDataContext();var 查询 = 来自 db.cdsItems 中的项目其中 items.ItemHandHeldFlag.Equals("Y") &&items.ItemQtyOnHand - items.ItemQtyCommitted >0选择项目;

此查询将库存状态从生产更新到商业站点.

解决方案

如果它只是 LINQ 中的 CASE 语句(阅读您的评论)然后是一个例子这是……

Int32[] numbers = new Int32[] { 1, 2, 1, 3, 1, 5, 3, 1 };var numberText =(从 n 数字其中 n >0选择新的{数 = n,文字 =(n == 1 ?一" :n == 2 ?二" :n == 3 ?三":未知")});

I need some help with CASE statements in linq (c#):

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  

My start at converting to linq, (I'm still learning):

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

This query updates stock status from production to a commerce site.

解决方案

If its just the CASE statement in LINQ your after (read your comment) then an example of this is...

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"
        )
    }
);

这篇关于linq case 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆