EntityEntry does not contain a definition for 'Reference'

asp.net-core entity-framework-core

Question

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?

1
1
9/28/2015 12:12:12 AM

Accepted Answer

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)

1
9/28/2015 4:04:07 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow