Entity Framework Core Eager Loading Then Include on a collection
For reference, the latest release (at the time of posting) EF Core 1.1.0 also supports explicit loading for this scenario. Something like this...
using (var _dbContext = new DbContext())
{
var sale = _dbContext.Sale
.Single(s => s.Id == 1);
_dbContext.Entry(sale)
.Collection(n => n.SalesNotes)
.Load();
_dbContext.Entry(sale)
.Reference(u => u.User)
.Load();
}
It doesn't matter that SaleNotes
is collection navigation property. It should work the same for references and collections:
_dbContext.Sale.Include(s => s.SaleNotes).ThenInclude(sn=>sn.User);
But as far I know, EF7 also supports the old multi-level Include syntax using Select extension method:
_dbContext.Sale.Include(s => s.SaleNotes.Select(sn=>sn.User));