实体框架4,更新具体属性 [英] Entity framework 4, update specific properties

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

问题描述

我习惯于先使用代码,我可以做的:

I'm used to using code first where I can do:

db.Users.Attach(user);
db.Entry(user).Property(propertyName).IsModified = true;

如何使用DataModel方法?

How do I do this with a DataModel approach?

我的datacontext上没有 Entry 方法。

I do not have the Entry method on my datacontext.

推荐答案

使用:

context.Users.Attach(user);
ObjectStateEntry entry = context.ObjectStateManager.GetObjectStateEntry(user);
entry.SetModifiedProperty(propertyName);

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

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