dbcontext 不包含“刷新"的定义 [英] dbcontext does not contain a definition for 'Refresh'
问题描述
我首先使用实体框架代码,但出现以下编译错误.dbcontext 不包含刷新"的定义.我见过很多使用 Refresh 方法的例子.但是当我将 Refresh 方法添加到我的 dbcontext 时,我得到了一个编译错误.我正在使用以下命名空间.
I'm working with the entity framework code first and am getting the following compilation error. dbcontext does not contain a definition for 'Refresh'. I have seen many examples where the Refresh method is being used. But when i add the Refresh method to my dbcontext I get a complilation error. I'm using the following namespaces.
using System.Data;
using System.Data.Entity;
using System.Data.Linq;
我错过了一个吗?我试图查找它,但没有找到命名空间.
Am I missing one? I tried to look it up but did not find the namespace.
推荐答案
DbContext 确实没有 Refresh() 方法.
DbContext does indeed not have a Refresh() method.
您看到的示例可能使用 ObjectContext.Refresh().
The examples you saw were probably using ObjectContext.Refresh().
你可以从另一个得到一个:
You can get one from the other:
db = new MyDbContext())
...
var ctx = ((IObjectContextAdapter)db).ObjectContext;
ctx.Refresh();
这个问题有更多关于细节和差异的信息.
This question has more about the details and differences.
这篇关于dbcontext 不包含“刷新"的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!