DBContext 不包含条目的定义:无法加载相关数据

DBContext does not contain a definition for Entry: Cannot load related data

当尝试加载相关数据并遵循 Explicit Loading of Related Data 上的指南时,我收到以下错误:

IApplicationDbcontext does not contain a definition for Entry.

我的示例代码与他们的类似,包括:

var person = _context.Persons.Single(p => p.PersonId = id);
_context.Entry(person).Collection(p => p.Addresses).Load();

我的情况的不同之处在于我正在注入一个看起来很标准的 IApplicationDbContext,我认为不会有什么不同:

public class ApplicationDbContext : DbContext, IApplicationDbContext
{
   ...
   public DbSet<Person> Persons { get; set; }
   public DbSet<Address> Addresses { get; set; }
   ...
}

我在这个项目中有 Microsoft.EntityFrameworkCore 5.0.7

您的 IApplicationDbContext 必须在其中声明以下方法签名才能工作。

EntityEntry<TEntity> Entry<TEntity>([NotNullAttribute] TEntity entity) where TEntity : class;