【发布时间】:2015-04-07 19:13:05
【问题描述】:
我一直在努力将下面的查询转换为 linq 查询,我非常接近,但我不确定如何将 case 语句添加到 LINQ。谷歌搜索让我如此接近。
原始工作查询:
SELECT *, CASE
WHEN Recipe_Name IN (SELECT Recipe_Name FROM Recipes WHERE Status = 2) THEN 0
ELSE 1
END AS editable
FROM Recipes WHERE Status = 1 ORDER BY Recipe_Name;
我的 LINQ - 缺少案例陈述:
var lcrecipes = from r in db.Recipes where r.Status == 2 select r.Recipe_Name;
var RecipeResults = from rr in db.Recipes where lcrecipes.Contains(rr.Recipe_Name) select rr;
我也试过了:
var RecipeResults = from rr in db.Recipes
where lcrecipes.Contains(rr.Recipe_Name)
select new
{
editable = rr.Status == 2 ? "false" :
rr.Status == 1 ? "true" : ""
};
如何将 case 语句合并到 LINQ 中?任何朝着正确方向的推动将不胜感激
【问题讨论】:
-
感谢投反对票
-
@Drewdin,我不知道谁对你的问题投了反对票,但我投了赞成票;)干杯,Maciej
标签: c# linq asp.net-mvc-3 subquery case