【问题标题】:EntityEntry<ApplicationUser> does not contain a definition for 'Reference'EntityEntry<ApplicationUser> 不包含“参考”的定义
【发布时间】:2015-09-28 00:12:12
【问题描述】:

如何在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 中定义的这个扩展方法在哪里?

【问题讨论】:

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


    【解决方案1】:

    从 beta7 开始,EF7 中还没有等价物。

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

    context.User.Include(u =&gt; u.Subjects)

    【讨论】:

      猜你喜欢
      • 2022-06-11
      • 2010-10-15
      • 2015-11-25
      • 2021-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-18
      • 1970-01-01
      相关资源
      最近更新 更多