Click here to Skip to main content
15,388,688 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +

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
Updated 10-Aug-20 23:59pm
Maciej Los 17-Mar-15 5:52am
What exactly have ou tried?
Hardeep Saggi 17-Mar-15 5:59am
Please explain more

1 solution

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

For further information, please see: How to: Perform Left Outer Joins (C# Programming Guide)[^]
[no name] 17-Mar-15 7:44am
+5 I love stored procedures! :-)
- Sebastian
Maciej Los 17-Mar-15 7:50am
Thank you, Sebastian ;)
jrafael83_2 14-Jun-19 12:32pm
This is great, but I faced the requirement of using Case in the Where. Is there any solution for this case?
Maciej Los 14-Jun-19 13:03pm
If you have any specific question, please don't hesitate to ask on QA forum. Use "Ask a question" widget on the left-top corner of this site. Then share the link to your question, i'll look up it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900