Linq查询使用Case语句 [英] Linq Query using Case statement

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

问题描述





我试图将下面的SQL查询转换为linq查询,但我无法做到。如果记录存在于另一个表中,我可以通过连接和连接如'*'这样的特殊字符来帮助如何使用这种类型的case语句。请帮我解决这个问题。



Hi,

I am trying to convert the below SQL query into linq query but am unable to do it. i can you please help how to usethis type of case statement by doing join and concatenation a special character like '*' if record exists in another table. Please help me how to do this.

Select Distinct A.MyID, Title + case when D.MyID is not null then ' *' else '' end  as Title , MagTitle FROM [MasterTitles] A left outer join TitleDetails D on A.[MyID] = D.[MyID] where [PropertyID] is not null ORDER BY [Title]









请帮助





Please help

推荐答案

它可能看起来像:

It might look like :
var qry = (from a in MasterTitles
          join d in TitleDetails on a.MyID equals d.MyID into grp
          from g in grp.DefaultIfEmpty()
          select new
          {
              MyID  = a.MyID,
              Title = grp != null ? string.Concat(a.Title, " *") : string.Empty
              //define next fields here
          }).Distinct();





如需了解更多信息,请参阅:如何:执行左外连接(C#编程指南) [ ^ ]


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

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