I have two tables, Kittens
and Owners
in my Entity Framework model. A Kitten
has 1 Owner
but an Owner
can have many Kitten
s.
I have a repository method called GetKittens()
that returns _context.Kittens.ToList();
Since I set up an association, I can do kitten.Owner.Name
.
But since ToList() was already called, and the context disposed of, how does it access the property? When retrieving an Entity, does it do a Join to all tables that have an association?
I have to write a query that pulls data from 4 tables, so I am wondering how to do this efficiently, hence this question trying to understand a bit more about how EF works.
Select
them andInclude (kitten => kitten.Owner).ToList ()
. – retailcoder 4 mins ago