[转]Entity Framework Refresh context?
本文转自:http://stackoverflow.com/questions/20270599/entity-framework-refresh-context
If you want to reload specific entities, with the DbContextApi, RX_DID_RX already gave you the answer.
If you want to reload / refresh all the entities you loaded:
If you are using Entity Framework 4.1+ (EF5, or EF 6 probably), DbContext API:
public void RefreshAll()
{
foreach (var entity in ctx.ChangeTracker.Entries())
{
entity.Reload();
}
}
Use the Refresh method:
context.Refresh(RefreshMode.StoreWins, yourEntity);
or in alternative dispose your current context and create a new one.
context.Reload() was not working for me in MVC 4, EF 5 so I did this.
context.Entry(entity).State = EntityState.Detached;
entity = context.Find(entity.ID);
http://stackoverflow.com/questions/15828811/entity-framework-caching-issue
|
If you know that changes happened outside of EF and want to refresh your ctxt for a specific entity, you can call ObjectContext.Refresh
If this seems like it will be a common occurance, you should disable object caching in your queries:
or for to turn off object level caching for specific Entity,
|
[转]Entity Framework Refresh context?的更多相关文章
- Entity Framework在Asp.net MVC中的实现One Context Per Request(附源码)
上篇中"Entity Framework中的Identity map和Unit of Work模式", 由于EF中的Identity map和Unit of Work模式,EF体现 ...
- Entity Framework : The model backing the '' context has changed since the database was created
1.采用code first 做项目时,数据库已经生成,后期修改数据库表结构.再次运行时出现一下问题: Entity Framework : The model backing the '' cont ...
- Entity Framework 6如何进行导航属性的筛选(context.Msg.First(t=>t.Id==1).Include(t=>t.MsgDetail),筛选MsgDetail带条件)
问题: https://q.cnblogs.com/q/98333/ Msg表(Id,Content,IsDel).内有 virtual ICollection<MsgDetail> Ms ...
- Entity Framework Context上下文管理(CallContext 数据槽)
Context上下文管理 Q1:脏数据 Q2:一次逻辑操作中,会多次访问数据库,增加了数据库服务器的压力 >在一次逻辑操作中实现上下文实例唯一 方法一:单例模式:内存的爆炸式增长 在整个运行期间 ...
- Entity Framework在Asp.net MVC中的实现One Context Per Request(转)
上篇中"Entity Framework中的Identity map和Unit of Work模式", 由于EF中的Identity map和Unit of Work模式,EF体现 ...
- Entity Framework context per request
原文发布时间为:2011-09-24 -- 来源于本人的百度文章 [由搬家工具导入] http://www.blog.cyberkinetx.com/2011/05/15/entity-framewo ...
- C# Entity Framework并发处理
原网站:C# Entity Framework并发处理 在软件开发过程中,并发控制是确保及时纠正由并发操作导致的错误的一种机制.从 ADO.NET 到 LINQ to SQL 再到如今的 ADO.NE ...
- Programming Entity Framework 翻译(1)-目录
1. Introducing the ADO.NET Entity Framework ado.net entity framework 介绍 1 The Entity Relationship Mo ...
- Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 创建复杂数据模型
Creating a complex data model 创建复杂数据模型 8 of 9 people found this helpful The Contoso University sampl ...
随机推荐
- 纸壳CMS 2.3,正式加入商城功能
纸壳CMS发布了2.3版本,主要是添加了商城功能,强化产品功能.让您的网站轻松实现电子商务. 有关2.3版本的更多信息,请查看以下链接: https://github.com/SeriaWei/ZKE ...
- 多线程DP
Matrix Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- 对Java意义重大的7个性能指标
本文中,小编搜集了7个最有影响的衡量标注,让你可以不依赖日志文件来了解应用程序现在,让我们看看这些性能指标,并了解如何查看并收集它们.: 一,响应时间和吞吐量 根据应用程序的响应时间可以知道程序完 ...
- 「案例」重新设计 Adobe 的文件类型图标
Adobe 的品牌设计团队负责为公司旗下桌面端.移动端和 web 端的产品进行品牌设计.品牌元素的形式很多,可以是两个字母的产品 logo,应用启动界面,产品里的图标等等. 一个很常见却常被忽视的品牌 ...
- 通过Nginx部署Django
Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式. 在这种方式中,我们的通常做法是,将nginx作为服务器最前端,它将接收WEB的所有请求,统一管理请求.ng ...
- SecureCRT上传下载文件
这篇内容在哪看到的我也找不到了,不过就是做个记录. 步骤如下: 1.SecureCRT连接远程终端. 2.在连接窗口上方右击,弹出菜单后点击Connect SFTP Session, 3.点击后弹出窗 ...
- thinkphp3.2----实现伪静态和路由配置
URL模式: 0.普通 http://localhost/qixin/ThinkCMF(test)_backup/index.php?g=user&m=login&a=index ...
- 适配器模式-如何把usb插到插座上
前言 下面所写的内容不是实际的业务场景, 也可能不符合正常的生活习惯, 或者不满足一些人的口味 所写的内容包括之前的帖子,只是为了方便大家更好的记住这个设计模式,实际生活中要灵活应用 设计模式重思想, ...
- mysql 2006 go away 错误
https://blog.csdn.net/yypsober/article/details/71330673 原文地址.
- mssqlServer大量数据快速插入:SqlBulkCopy
SqlBulkCopy类,为微软的一个大量数据快速插入.直接上代码 表结构: namespace SqlBulkCopy的演示 { using System.Data.SqlClient; publi ...