C#C
C#11mo ago
6 replies
A Ka Sup

Left join 2 or more tables with 1-n relationship

guys, i have tableA, B with relation 1 A - n B. so i can get the data from A with leftjoin like this
context.TableA
       .GroupJoin(context.TableB,
           a => a.Id,
           b => b.IdA,
           (a, b) => new { a, b = b.DefaultIfEmpty() }
       )
       .SelectMany(s => s.b, (s, b) => {
           Stuff = b.Stuff,
       })

but now i have other tableC, with relation 1 A - n C. so how do i get the data from A, with left join to B and C?
the result i want
{ Stuff = b.Stuff, Stuff2 = c.Stuff2 }
Was this page helpful?