实体框架附加更新不工作 [英] Entity framework attach update not working

查看:98
本文介绍了实体框架附加更新不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  context.Jobs.Attach()工作); 
context.SaveChanges();

这不行。没有错误被抛出,它只是不更新​​数据库中的值。



我试过:

  context.Jobs.AttachTo(Jobs,job); 
context.SaveChanges();

没有任何错误,仍然没有错误,没有更新。

解决方案

如何更改 ObjectState

  context.ObjectStateManager.ChangeObjectState(job,System.Data.EntityState.Modified); 

从MSDN: ObjectStateManager.ChangeObjectState方法


I'm trying to update a POCO object using entity framework in the following way:

 context.Jobs.Attach(job);
 context.SaveChanges();

That does not work. No error is thrown, it just isn't updating the values in the database.

I tried:

context.Jobs.AttachTo("Jobs", job);
context.SaveChanges();

Nothing wrongs, still no error and no updates.

解决方案

What about changing the ObjectState?

context.ObjectStateManager.ChangeObjectState(job, System.Data.EntityState.Modified);

From MSDN: ObjectStateManager.ChangeObjectState Method.

这篇关于实体框架附加更新不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆