ASP.NET - WCF - EF4代码优先:如何进行更新 [英] ASP.NET - WCF - EF4 Code First: How can I do updates

查看:62
本文介绍了ASP.NET - WCF - EF4代码优先:如何进行更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用WCF服务检索对象并对其进行修改。


使用EF4对象上下文我使用ctx.ObjectStateManager.ChangeObjectState(Me,EntityState.Modified)来标记以前附加的对象已修改。使用DBContext我只能添加或附加。这意味着EntityState是添加或不变。


如果我使用Find方法检查对象是否已经存在,我不能再使用Attach了,因为该对象已经在上下文中加载了使用原始值。


我希望有类似更新的内容,或者更好的是,可以使用更新的值重新附加对象,并检查是否存在是改变了。应该相应地设置EntityState。 支票
应该包括对象图。


有什么计划?

解决方案

我们正在研究提供更新方法或类似方法。 我们目前还不确定它到底会是什么样子,但我们确实希望确保它适用于您描述的场景,包括使用
并发令牌执行适当的操作。


现在,您仍然可以下拉到ObjectContext,然后使用上面显示的相同机制将状态标记为已修改。


关于使用查找然后附加的观点是一个很好的,我们会考虑周围的事情。


谢谢,

亚瑟


 


I retrieve an object using a WCF Service and modify it.

With the EF4 object context I used ctx.ObjectStateManager.ChangeObjectState(Me, EntityState.Modified) to mark the formerly attached object as modified. Using the DBContext I can only add or attach. Which means that the EntityState is either Added or Unchanged.

If I use the Find method to check if the object already exists I cannot use Attach anymore because the object is already loaded in the context with the original values.

I wished there was something like Update or even better that there was the possibility to re-attach the object with the updated values and check if there were changes made. The EntityState should be set accordingly. The check should include the object graphs.

What are the plans?

解决方案

We are looking into providing an Update method or something similar.  We're not sure exactly what it will look like at this point, but we do want to make sure that it works well for the scenarios you describe, including doing appropriate things with concurrency tokens.

For now, you can still drop down to the ObjectContext and then use the same mechanisms you show above to mark the state as modified.

Your point about using Find then Attach is a good one and we'll do some thinking around that.

Thanks,
Arthur

 


这篇关于ASP.NET - WCF - EF4代码优先:如何进行更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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