LINQ case语句 [英] linq case statement
本文介绍了LINQ case语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一些帮助与LINQ CASE语句(C#):
osc_products.products_quantity =
案件
WHEN itempromoflag<> 'N'THEN 100000
WHEN itemcat1 IN('1','2','31')与itemsalestatus =STHEN 100000
WHEN itemsalestatus ='O',那么0
ELSE cds_oeinvitem.itemqtyonhand - cds_oeinvitem.itemqtycommitted
结束
我在转换为LINQ的开始,(我还在学习):
cdsDBDataContext DB =新cdsDBDataContext();
VAR查询从db.cdsItems项目=
其中,items.ItemHandHeldFlag.Equals(Y)及与放大器;
items.ItemQtyOnHand - items.ItemQtyCommitted> 0
选择项目;
块引用>该查询从生产更新库存状态,以一个电子商务网站。
谢谢!
解决方案如果它只是在 CASE 语句中的 LINQ 您后(读您的评论),那么的例子这是...
的Int32 []号=新的Int32 [] {1,2,1,3,1,5,3,1};VAR numberText =
(
从个数n
其中n> 0
新选择
{
数= N,
文字=
(
ñ== 1? 一:
ñ== 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.
Thanks !!!
解决方案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" ) } );
Hope that helps :)
这篇关于LINQ case语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文