Given the following 3 (simplified) classes:
- ClassA { int Id; }
- ClassB { int Id; }
- JunctionClass { ClassA classA; ClassB classB; }
When I am trying to load the JunctionClass list...
var junctionClassList = _appDbContext.JunctionClass
.Include(jc => jc.ClassA)
.Include(jc => jc.ClassB).ToList();
the code doesn't load the ClassA and ClassB objects.
I have found a fix, but I don't think that I'm using EF Core the way it should be used:
var classAList = _appDbContext.ClassA.ToList();
var classBList = _appDbContext.ClassB.ToList();
var junctionClassList = _appDbContext.JunctionClass
.Include(jc => jc.ClassA)
.Include(jc => jc.ClassB).ToList();
This way, the junctionClassList object will also load the classA and classB dependencies.
My question is this - is this the correct way to use lazy/eager loading? Or is there another way?