I can I generate the below SQL query select using entity framework core 3.1.8 ?
SELECT *
FROM table1 t1
LEFT JOIN table2 t2 ON t1.Id = t2.table1Id AND t2.Status IN (1,2,3)
I tried the code below
var statuses = new List<int> { 1, 2, 3 };
var result = await (from t1 in _context.Table1
join t2 in _context.Table2
on t1.Id equals t2.TableId
into results
from m in results.Where(x => statuses.Contains((int)x.Status)).DefaultIfEmpty()
select new ResultDto
{
}).ToListAsync();
But the query generates a suquery
UPDATED
The query suggested by
@Svyatoslav Danyliv generated the SQL
below
SELECT [a].[Id], [a].[ActionWith], [a].[CreatedBy], [a].[DateCreated], [t].[table1Id], [t].[Comment], [t].[CreatedBy], [t].[DateCreated]
FROM [Table1] AS [a]
LEFT JOIN (
SELECT [c].[Id], [c].[table1Id], [c].[Comment], [c].[CreatedBy], [c].[DateCreated]
FROM [Table2] AS [c]
WHERE [c].[Status] IN (1, 2)
) AS [t] ON [a].[Id] = [t].[table1Id]