The EF Core docs on lazy loading without proxies reference this example:
public class Blog
{
private ICollection<Post> _posts;
public Blog()
{
}
private Blog(ILazyLoader lazyLoader)
{
LazyLoader = lazyLoader;
}
private ILazyLoader LazyLoader { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Post> Posts
{
get => LazyLoader.Load(this, ref _posts);
set => _posts = value;
}
}
So we have a parameterless constructor and the lazy loader injection constructor. The docs then say this:
This method doesn't require entity types to be inherited from or navigation properties to be virtual, and allows entity instances created with new to lazy-load once attached to a context.
So what does this mean exactly for new instances? An entity created by EF core will have the lazy loader injected but a new entity will not. Does this imply that once a new item is added to the context the lazy loader backing field should get updated?