How do I specify in EF7
that I wish to explicitly load the reference property Subject of my ApplicationUser entity? In EF6 the following is defined in the namespace System.Data.EntityFramework.Infrastructure
:
public DbReferenceEntry<TEntity, TProperty> Reference<TProperty>(Expression<Func<TEntity, TProperty>> navigationProperty) where TProperty : class;
So this code:
public async override Task<ApplicationUser> FindByIdAsync(string userId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
var user = await base.FindByIdAsync(userId);
this.Context.Entry(user).Reference(u => u.Subjects).Load();
return user;
}
gives an exception
EntityEntry<ApplicationUser> does not contain a definition for 'Reference'.
Where is this extension method defined in EF7
?
There is no equivalent yet in EF7 as of beta7.
To include related entities, use eager loading with the .Include()
method in your query.
context.User.Include(u => u.Subjects)