【发布时间】:2013-11-27 07:35:44
【问题描述】:
这是我的字符串 sql 查询,但我无法将其转换为 linq,因为它包含基于 where 子句的案例,我们将不胜感激。
if (StrClientID.Equals("008"))
objdbhims.Query += " and (( case when t.external_org is null then d.clientid='008' end) or t.external_org in ('008','-1'))";
else if (StrClientID.Equals("006"))
objdbhims.Query += " and (t.external_org<>'008' or (case when t.external_org is null then d.clientid='" + StrClientID + "' end))";
else
objdbhims.Query += " and d.clientid='"+StrClientID+"'";
【问题讨论】:
-
你可以在linq中使用三元运算符
<test> ? <valueiftrue> : <valueiffalse> -
@RaphaëlAlthaus case statement replace is if else but in ternary operator when I do
? 并且我不放 else 部分它给出了语法错误,我不想要 else 部分,怎么做/ -
那么你可以在第二部分中添加类似
m => true的内容... -
@RaphaëlAlthaus 谢谢你的建议作为魅力...:)
标签: c# sql linq linq-to-sql linq-to-entities