gpt4 book ai didi

c# - 找不到类型或命名空间名称 'DbEntityEntry'

转载 作者:太空宇宙 更新时间:2023-11-03 19:55:08 28 4
gpt4 key购买 nike

我有以下在 EF7 之前使用的界面。当我尝试使用 EF7 构建应用程序时,我收到以下错误,而且我似乎无法在任何地方找到这种类型。我非常感谢您就如何为 EF7 更改此代码提出建议。

Error CS0246 The type or namespace name 'DbEntityEntry' could not be found (are you missing a using directive or an assembly reference?)

public interface IContext
{
DbSet<Client> Clients { get; set; }
DbSet<TEntity> Set<TEntity>() where TEntity : class;

DbEntityEntry<TEntity> Entry<TEntity>(TEntity entity) where TEntity : class;

int SaveChanges();
}

最佳答案

Entity Framework 7 中没有 DbEntityEntry 类型。整个底层更改跟踪实现已更改,并且没有对此的精确复制。

有一个EntityEntry在新的 Microsoft.Data.Entity.ChangeTracking 命名空间中键入,它具有类似的目的,但它的工作方式有点不同,因为它与 DbEntityEntry 不兼容。输入早期版本的 Entity Framework。

您可以从 ChangeTracker 访问它可通过 DbContext.ChangeTracker 访问。

但是至于保留该界面,这不太可能对您有帮助,因为很多事情都发生了变化。

关于c# - 找不到类型或命名空间名称 'DbEntityEntry<TEntity>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34534310/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com