dbcontext does not contain a definition for #39;Refresh#39;(dbcontext 不包含“刷新的定义)
问题描述
我首先使用实体框架代码,但出现以下编译错误.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 不包含“刷新"的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:dbcontext 不包含“刷新"的定义


- C#MongoDB使用Builders查找派生对象 2022-09-04
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01