在使用Entity Framework加载关联实体时,可以有三种方式: 1.懒加载(lazy Loading); 2.贪婪加载(eager loading); 3.显示加载(explicit loading). EF默认使用的是懒加载(lazy Loading).一切由EF自动处理. 这种方式会导致应用程序多次连接数据库,这种情况推荐在数据量较大的情况下使用.当我们需要加载数据较少时,一次性全部加载数据会相对更高效. 我们来看看EF的显示加载(explicit loading)如何让我们完全掌控…
上篇中"Entity Framework中的Identity map和Unit of Work模式", 由于EF中的Identity map和Unit of Work模式,EF体现出来如下特性: 唯一性: 在一个Context的生命周期中,一个Entity只会有一个实例,任何对该实例的修改,即使这些改动没有保存到数据库中,修改都会影响到整个Context的生命周期. 事务性: 所有对于Entity的修改,都会在调用SaveChange方法的时候,一起保存到数据库中,最终实现持久化. 下…
关于Repository模式,在这篇文章中有介绍,Entity Framework返回IEnumerable还是IQueryable? 这篇文章介绍的是使用Entity Framework实现的Repositoy模式设计,欢迎各位拍砖. 阅读目录: 一.实现的思路和结构图 二.Repository设计具体的实现代码 三.Repository设计的具体的使用 四.总结 一,实现的思路和结构图 总结一下,Repository在实际使用中,有下面三种特点: Repository的共同性 有一些公共的方…
Explicit Loading with DBContext Even with lazy loading disabled, it is still possible to lazily load related entities, but it must be done with an explicit call. Use the Load method of DBEntityEntry object to accomplish this. The following code expli…
在学习python开发框架pylons/pyramid的过程中,里面有个非常棒的页面性能监控功能,这样在开发过程中,你能清楚的知道当前页面的性能以及其它参数. 这里介绍一下如何给Asp.net MVC和Entity Framework也添加上性能监控,让你在开发过程中随时掌握当前程序运行的信息. 这里是在Autofac+MVC+EF篇的源码基础上,一步一步的介绍添加Profiler的过程. 如果有兴趣了解Autofac的应用,可以看这里 IoC容器Autofac(4) - Autofact +…
Lazy Loading: One of the important functions of Entity Framework is lazy loading. Lazy loading means delaying the loading of related data, until you specifically request for it. For example, Student class contains StudentAddress as a complex property…
Eager Loading: Eager loading is the process whereby a query for one type of entity also loads related entities as part of the query. Eager loading is achieved using the Include() method. In the following example, it gets all the students from the dat…
我们知道,Web开发上有很多HTML的编辑控件,如FCKEditor.CKEditor.kindeditor等等,很多都做的很好,而虽然Winform里面有WebBrowser控件,但是默认这个控件是不允许编辑内容的,可以显示网页而已.Winform开发里面,有些使用RichTextBox控件来编辑HTML,也有一些结合WebBrowser控件来实现内容的编辑,其中我觉得做的最好的应该是Zeta HTML Edit Control(http://www.codeproject.com/Artic…
阅读目录: 一.什么是Identity map模式 二.关于Identity map模式的验证示例 三.Unit of Work 模式 四.总结和注意的问题 一,什么是Identity map模式 Identity map是EF获取和缓存数据的模式.Identity map模式指的是任何数据都只会被加载一次,以map的形式缓存,以唯一的identity来再次获取这些数据.在EF中,就是在一个Context的生命周期中,所有查询过的数据都会缓存到Context的local中缓存.当再次访问这些数据…
一,什么是Identity map模式 Identity map是EF获取和缓存数据的模式.Identity map模式指的是任何数据都只会被加载一次,以map的形式缓存,以唯一的identity来再次获取这些数据.在EF中,就是在一个Context的生命周期中,所有查询过的数据都会缓存到Context的local中缓存.当再次访问这些数据的时候,就会以主键(identity)从缓存中获取这些数据. 二,关于Identity map模式的验证示例 看看下面这段代码运行的结果: using (va…