gpt4 book ai didi

entity-framework - context.Entry()在哪里?

转载 作者:行者123 更新时间:2023-12-03 09:22:34 25 4
gpt4 key购买 nike

我通过阅读this article和许多其他语言来编写自己的上下文,但是主题都没有解释此context.Entry(obj)的定义位置,我的意思是即使阅读this article,我也无法理解如何实现此方法,并且出现以下错误:

Error 36 'Domain.Entities.OurWebSiteContext' does not contain a definition for 'Entry' and no extension method 'Entry' accepting a first argument of type 'Domain.Entities.OurWebSiteContext' could be found (are you missing a using directive or an assembly reference?)



有人帮我

编辑>>
 public class OurWebSiteContext : DbContext
{
public OurWebSiteContext(string connString)
: base(connString)
{

}

public DbSet<Article> Articles { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Comment> Comments { get; set; }
}

最佳答案

可能为时已晚,但可能会对其他人有所帮助,EF 4.0使用ObjectContext类,其中版本4.1使用DbContext类,其中定义了诸如Set<T>Entry之类的方法。使用4.0版,您可以执行以下操作

DatabaseContext _context = new DatabaseContext();
_context.ObjectStateManager.ChangeObjectState(entity, System.Data.EntityState.Modified);

与版本4.1一样完成
_context.Entry(entity).State = System.Data.EntityState.Modified;

这是一个有用的 SO link

关于entity-framework - context.Entry()在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7113434/

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