I need to convert the following SQL select statement below to its LINQ equivalent.
SQL STATEMENT:
SELECT MainTitles.Title,
SubTitles.Title,
ContentResources.ResourceContent,
SubTitles.MainTitleId,
SubTitles.SubTitleId
FROM ContentResources
LEFT JOIN MainTitles on ContentResources.MainTitleId = MainTitles.MainTitleId
LEFT JOIN SubTitles on ContentResources.ContentResourceId = SubTitles.ContentResourceId
TABLE SAMPLES:
Table Structure with Sample Data
RESULT OF THE STATEMENT:
The desired result using SQL is shown in the screenshot below.
[
WHAT I HAVE TRIED IN LINQ
var resources = (from c in _context.ContentResources
join m in _context.MainTitles
on c.MainTitleId equals m.MainTitleId into ResultTable1
from result in ResultTable1.DefaultIfEmpty()
join s in _context.SubTitles
on c.ContentResourceId equals s.SubTitleId
on c.ContentResourceId equals s.SubTitleId into ResultTable2
from result2 in ResultTable2.DefaultIfEmpty()
select new
{
c.ResourceContent,
c.ContentResourceId,
c.MainTitleId,
result.Title,
s.SubTitle
}).ToList();
Please help me. I have seen for 1 Left Join and that is how I was able to try what I have above. I even tried the free version of LINQPad7 but I have no idea how to convert the SQL to LINQ using it. Thanks in advance.
