在实体框架中保存断开的对象4 [英] Save disconnected object in entity framework 4

查看:90
本文介绍了在实体框架中保存断开的对象4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在EF1中,我不能只是在ObjectContext的范围之外更新构造的对象(具有正确的id)。

in EF1, i couldn't just update an object that was constructed (with the right id) outside the scope of the ObjectContext.

有没有新的方法在EF4?

Is there a new way in EF4?

我可以将其添加到上下文(context.AddOrder(order))(其中context是我的ObjectContext的一个实例),它看到它有一个id并更新它?

Can i just add it to the context (context.AddOrder(order)) (where context is an instance of my ObjectContext) and 'it' sees that it has an id and updates it?

这是非poco,所以我的对象从 EntityObject

It's non-poco so my objects derive from EntityObject

推荐答案

使用附加方法。它是为断开的对象设计的。

Use the Attach method instead. It is designed for disconnected objects.

这篇关于在实体框架中保存断开的对象4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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