EF 4.3 - 更新相关实体 [英] EF 4.3 - Update related entities

查看:94
本文介绍了EF 4.3 - 更新相关实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

可能已经回答了这个问题,但我无法找到解决问题的方法。基本上我使用include语句加载具有子实体的实体。如果对父实体和子实体都进行了更改,则只会更新父

Probably this has been already answered but i couldn't find the appropriate solution to my problem. Basically i'm loading entities with sub entities using the include statement. When change is done to both the parent and child entities only the parent gets updated.

对于更新,我正在执行以下操作:

For update i'm doing the following:

DbContext.Entry<TEntity>(entity).State = EntityState.Modified;


要解决我的问题,我还需要上面的子实体吗?如果是这样,是否有适当的(通用)方式来执行此操作?

To solve my problem would i need to the above for child entities too? If so, is there an approriate (generic) way to do this?

推荐答案

嗨Syslock,

欢迎来到MSDN论坛。

你用哪种方式?代码优先,数据库优先或模型优先?

通常情况下,如果将实体加载到内存中,对象上下文将跟踪其状态并自动更改其状态。您能否提供更新相关实体的代码?

美好的一天。


这篇关于EF 4.3 - 更新相关实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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