When using EF Core's ILazyLoader for lazy loading without proxies, calling DbSet<T>.Add() immediately injects the lazy loader into the entity via reflection — before SaveChangesAsync() is called. This means accessing a navigation property on a newly added but unsaved entity triggers a pointless database query (e.g., WHERE BlogId = 0). The fix is simple: keep the entity disconnected from the DbContext until you're ready to save, then call Add() right before SaveChangesAsync().

4m read timeFrom markheath.net
Post cover image
Table of contents
The ModelReproducing The ProblemThe SolutionSummary