试图在这里处理EntityFramework,但我遇到了一些减速带......我有一个Get()方法可以正常工作并且已经过测试,但是我的Delete方法不起作用:publicstaticvoidDelete(stringname){J1Entitiesdb=newJ1Entities();db.DeleteObject(Get(name));db.SaveChanges();}但是我收到以下错误:错误:无法删除该对象,因为在ObjectStateManager中找不到它。我运行了调试器,DeleteObject中的对象是正确的...我错过了什么?谢谢。 最佳
当我尝试从EntityFramework4在我的数据库上下文中调用它时,出现“无法解析符号ObjectStateManager”错误。我找不到其他人有此问题。我试过使用System.Data和System.Data.Objects。是否需要创建特定的EntityFramework才能使用ObjectStateManager?或者我是否缺少某种安装包?我正在使用数据库优先EntityFramework。这是给我错误的代码:(第7行)[HttpPost]publicActionResultEditProfile(Useruser){if(ModelState.IsValid){db.Use
我正在尝试使用EntityFramework5删除对象,但出现此错误。无法删除该对象,因为在ObjectStateManager中找不到它我正在使用Remove()方法,因为EF5中不存在DeleteObject()。任何人都可以帮助我缺少什么吗?这不适用于移除localDb.Customers.Remove(newCustomer(){CustomerId=id});localDb.SaveChanges();我尝试从msdn将状态更改为已删除的另一件事。但是这里它给出了一个错误,说所有的字段都应该存在。是否需要获取完整的记录再删除?varcustomer=newCustomer()
当我尝试将实体附加到上下文时出现异常AnobjectwiththesamekeyalreadyexistsintheObjectStateManager.TheObjectStateManagercannottrackmultipleobjectswiththesamekey这是预期的行为。但我想知道ObjectStateManager是如何知道的?我想先自己做这个检查 最佳答案 如果您正在使用DbContextAPI(您提到了ef-code-first),您可以简单地使用:context.YourEntities.Local.An
当我尝试将实体附加到上下文时出现异常AnobjectwiththesamekeyalreadyexistsintheObjectStateManager.TheObjectStateManagercannottrackmultipleobjectswiththesamekey这是预期的行为。但我想知道ObjectStateManager是如何知道的?我想先自己做这个检查 最佳答案 如果您正在使用DbContextAPI(您提到了ef-code-first),您可以简单地使用:context.YourEntities.Local.An
我需要从我的数据库上下文中返回一个新添加对象的列表。我读到我必须为此目的使用ObjectStateManager。问题是,我的数据库上下文没有ObjectStateManager属性。尽管上下文可以很好地检索、添加和更新对象。我正在使用EF5.0我能做什么? 最佳答案 试试这个:varmanager=((IObjectContextAdapter)dbContext).ObjectContext.ObjectStateManager; 关于c#-为什么我的数据库上下文中不存在Object
使用带有通用存储库模式的EF5和ninject进行依赖注入(inject),并在尝试使用我的edmx使用存储过程将实体更新到数据库时遇到问题。我在DbContextRepository.cs中的更新是:publicoverridevoidUpdate(Tentity){if(entity==null)thrownewArgumentException("Cannotaddanullentity.");varentry=_context.Entry(entity);if(entry.State==EntityState.Detached){_context.Set().Attach(en
我收到此错误“无法删除该对象,因为在ObjectStateManager中找不到它。”我的代码是:protectedMyEntitiessqlEntities;publicvirtualvoidDelete(TEntityentity){System.Typet=typeof(TEntity);sqlEntities.DeleteObject(entity);sqlEntities.SaveChanges();} 最佳答案 这意味着实体没有附加(它不是由同一个上下文实例加载的)。试试这个:protectedMyEntitiessql