locked
EF left or right join RRS feed

  • Question

  • User1183902823 posted

    see the query

    var answer = (from c in db.customers 
                  join p in db.purchases 
                  on c.ID = p.CustomerID into subs
                  from sub in subs.DefaultIfEmpty()
                  group sub by new { c.ID, c.Name } into gr
                  select new {
                      gr.Key.ID,
                      gr.Key.Name,
                      Total = gr.Count(x => x != null),
                      CountCompleted = gr.Count(x => x != null && x.CompletedTransaction)
                  }).ToList();
    
    

    the above join is left or right join?

    i got the above join hint from these url

    https://stackoverflow.com/a/8055893/6188148
    https://stackoverflow.com/a/46947013/6188148

    how to determine what kind of join is it ?

    thanks

    Thursday, January 18, 2018 10:55 AM

Answers

  • User1400794712 posted

    Hi tridip1974,

    Actually, the code you post here can be said both left and right join.

    For customers and purchases, it's left join.

    For purchases and customers, it's right join.

    There is no obvious division between them.

    Best Regards,

    Daisy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 19, 2018 7:08 AM

All replies

  • User1400794712 posted

    Hi tridip1974,

    Actually, the code you post here can be said both left and right join.

    For customers and purchases, it's left join.

    For purchases and customers, it's right join.

    There is no obvious division between them.

    Best Regards,

    Daisy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 19, 2018 7:08 AM
  • User1183902823 posted

    you said --

    For customers and purchases, it's left join.

    For purchases and customers, it's right join.

    this is not clear what you try to say.

    it is very confusing that we can not say the join is left or right. it would be great if we could use left or right keyword at the time EF linq join query.

    Friday, January 19, 2018 7:55 AM