EntityEntry <applicationuser>不包含&#39;参考&#39;的定义。

时间:2015-09-28 00:12:12

标签: asp.net-core entity-framework-core

如何在EF7中指定我希望显式加载ApplicationUser实体的引用属性Subject?在EF6中,名称空间System.Data.EntityFramework.Infrastructure中定义了以下内容:

public DbReferenceEntry<TEntity, TProperty> Reference<TProperty>(Expression<Func<TEntity, TProperty>> navigationProperty) where TProperty : class;

所以这段代码:

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;
    }

给出例外

EntityEntry<ApplicationUser> does not contain a definition for 'Reference'.

EF7中定义的此扩展方法在哪里?

1 个答案:

答案 0 :(得分:1)

在EF7中还没有与beta7相同的内容。

要包含相关实体,请在查询中使用.Include()方法进行预先加载。

context.User.Include(u => u.Subjects)