2

Suppose i have

    class A
        {
            int id;
            IQueryable<B> bs;
        }
        class B
        {
            int id;
            int AId;
            IQueryable<C> cs;
        }
        class C
        {
            int id;
    int AID
            int Bid;

        }
and in sql i could join them like
    select * from A
    left join b on a.Id = B.AID
    left join c on a.ID = c.AId and b.id = c.bID

How could i do that with a lambda? I know in general left join is done with group join, but i don't see how to get the keys needed for c

user1058410
  • 135
  • 1
  • 9
  • 1
    Does this answer your question? Look at answers, with lambda [LEFT OUTER JOIN in LINQ](https://stackoverflow.com/questions/3404975/left-outer-join-in-linq) – T.S. Feb 27 '20 at 20:32
  • Not really. I can get the first join to work just fine, which is what they're doing in the example. My problem comes in joining the third type – user1058410 Feb 27 '20 at 21:41
  • This is probably a nice academic problem but in the real world you're wasting your time because straight LINQ is way faster than lambda joins when you work with object collections. And if you endup with Linq-to-sql, you also may have bad query in the end. I already went through exercise of replacing all our lambdas (with joins) with LINQ because of performance (linq to objects) and query correctness (LTS). – T.S. Feb 27 '20 at 22:08
  • I haven't noticed a problem with performance. maybe you're dealing with bigger datasets than i am, but you're right about it being largely an academic problem, as i can easily solve my own question using ado and executing the sql which will be faster than either. – user1058410 Feb 27 '20 at 22:46
  • From my old work email: `var data = from a in listA from b in listB.Where(x => x.Id == a.Id) select a; // ~ 3.5 sec` and `var data = from a in listA join b in listB on a.Id equals b.Id select a; // ~ 0.03 sec` – T.S. Feb 28 '20 at 00:49
  • Turns out after messing with it on and off most of the day, what i was trying can't be done with the version of Entity Framework I'm using, efcore 3. Group by isn't supported in method syntax so yay – user1058410 Feb 28 '20 at 02:23

1 Answers1

0

This can't be done currently with the version of Entity Framework i was using, ef core 3.0, as it doesn't support group join. Hopefully this will change

user1058410
  • 135
  • 1
  • 9