When Lazy Loading is enabled, the navigation property (linked entity or collection of entities) gets automatically loaded when you access it for the first time. That's why album.Genre would work fine as long as the DbContext is not yet disposed or if the Genre property (of a certain Album) has been accessed before.
When Lazy Loading is disabled, you don't have that flexibility. You need to eagerly (or explicitly) load the linked entities. You are off to the right start by using Include() (Eagerly Loading). However, since albums is not yet materialized (not loaded into memory), attempting to access the Genre property by executing a different query (which is what db.Albums.Find() does) will fail.
You have two options here...
Materialize the query:
var albums = db.Albums.Include(a => a.Artist).Include(a => a.Genre).ToList();
Album album = db.Albums.Find(id);
// Works because all `Album.Genre` **of all `Album` records** is loaded into the EF cache.
var name = album.Genre.Name;
Find the target Album using the same query that includes linked entities:
var albums = db.Albums.Include(a => a.Artist).Include(a => a.Genre)
// This will force EF to load the "included" entities for this one specific record.
Album album = albums.FirstOrDefault(a => a.Id == id);
var name = album.Genre.Name;
db.Albums.Find()executes a separate query. UseAlbum album = albums.FirstOrDefault(a => a.Id == id);. Then, you can accessalbum.Genre. - 41686d6564db? Once they are in the change tracker, they should be linked. - Jeremy Lakemanalbumsquery is actually loaded into memory (which is not the case here). Callingalbums.ToList()oralbums.Load()should do the trick. - 41686d6564