无法获取ApplyCurrentValues(实体)的实体框架5工作 [英] Can't get the ApplyCurrentValues(Entity) to work in Entity Framework 5

查看:150
本文介绍了无法获取ApplyCurrentValues(实体)的实体框架5工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

同志们,谁能帮助我在这里,实体框架5似乎没有ApplyCurrentValues()方法。有另一种方式来更新实体框架V5数据库对象。这里是我想要做

Comrades, can anyone help me out here, entity framework 5 seems not to have ApplyCurrentValues() method. Is there another way to update the database object in entity framework v5. here is what am trying to do

odc.Accounts.Attach(new Account { AccountID = account.AccountID });
  odc.Accounts.ApplyCurrentValues(account);
  odc.SaveChanges();



但我已经越来越在 ApplyCurrentValues编译错误()

推荐答案

ApplyCurrentValues 的ObjectContext API方法,所以首先你要访问的是包裹在的DbContext ObjectContext中:

ApplyCurrentValues is an ObjectContext API method, so first you have to gain access to the objectcontext that is wrapped in the DbContext:

odc.Accounts.Attach(new Account { AccountID = account.AccountID });
((IObjectContextAdapter)odc).ObjectContext
    .ApplyCurrentValues("Accounts", account);
odc.SaveChanges();

请注意,该包裹的上下文没有会员像帐户,所以你必须使用< 。code>的ObjectContext 方法本身

Note that the wrapped context does not have members like "Accounts", so you have to use the ObjectContext method itself.

但是你可以做使用的DbContext API相同的:

But you can do the same using the DbContext API:

var sourceAcc = new Account { AccountID = account.AccountID });
odc.Entry(account).CurrentValues.SetValues(sourceAcc);

这篇关于无法获取ApplyCurrentValues(实体)的实体框架5工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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