IMPLEMENTATION - Entity Framework Anti Pattern - High Performance EF

Good about ORM
- Developer is free from building T-Sql on the database tier which is not their major area.
- Rapid development
- Strongly typed object to ensure data type match with C# type
Page life expectancy
Database data records stored in pages which is 8kb per page, when the data being query, the relevant pages will be load into db memory for futher proccess. and they will stay in the memory until the memory is full and need to clean up the staled pages and make the room for pages required for the new queries.

Cluster indexed scan vs seeking
cluster index *scan* mean reading all data top to bottom cluster index *seeking* is way better than scan cuz it does filter on index so dont filter at client look at client statodtic on client receive bytes from server to understand improvement on byte traffic reduction

explicit join better than nested linq. join is more tsql style. lambda expression is oo better than explicit join.
| nested linq | explicit join | lambda expression |
|
![]() |
![]() |
code first has the benefit of source agnostic. but choosing the right data type is also impotant for performance.
datatype auto generate by ef raise concern to cost and perf. nvarchar vs varchar. taking up different size of space given they storing same amount data.

imagine how is that affect and cascade to replica for HA. BI and bulk load jobs.
also it affects performance as there are extra spaces kept for the same record. remember db engine use page to cache data for plan execution. db type not being evaluated will result in high db memory usage.
data type is critical in a sense that even the same record is stored, with different data type. the record dump to the page can be high as 79m down to 51b (without other changes like adding index) . overstated data type will result in resource dramatically overused.
|
![]() |
ef offers the capabiloty of altering the datatype and length when exec the code first code to deploy to db. annotation of maxlengh or required can be defined at field level at poco or in a builder context object via fluent API, .IsUniCode mandate the string field map to a varchar rather than nvarchar (for Unicode for cross culture) which is double in size when storing the same data.

lazy loading is like you watching the online movie, you can view the first 10 mins w/o downloading complete clip to get start.
it fit for use when user navigation is uncertained. lamda expression of 'skip' can privide some support. once lazy load is set in ef all reading of the ref table is return null.
eager loading in contrast is aim for the use case that consumer of the data collection having predefine routine to navigate the reference data sets.
ef allows you to add interceptor to change its default crud operation by overwrite e.g. the delete clause to soft delete rather than hard delete.
In summary, 3 type of potential issues need to be considered.

indexing. cluster index, pointer that sorting the teference the table record. non cluster, pointers to the clustered index which itself is sorted. each of them has the overhead and size increase when record inserted or deleted.
when ef cannot performas expected, back to use the good old sp.
IMPLEMENTATION - Entity Framework Anti Pattern - High Performance EF的更多相关文章
- 21.翻译系列:Entity Framework 6 Power Tools【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/entity-framework-power-tools.aspx 大家好,这里就是EF ...
- ADO.NET Entity Framework CodeFirst 如何输出日志(EF 5.0)
ADO.NET Entity Framework CodeFirst 如何输出日志(EF4.3) 用的EFProviderWrappers ,这个组件好久没有更新了,对于SQL执行日志的解决方案的需求 ...
- Entity Framework 5.0系列之EF概览
概述 在开发面向数据的软件时我们常常为了解决业务问题实体.关系和逻辑构建模型而费尽心机,ORM的产生为我们提供了一种优雅的解决方案.ADO.NET Entity Framework是.NET开发中一种 ...
- Entity Framework 学习中级篇1—EF支持复杂类型的实现
本节,将介绍如何手动构造复杂类型(ComplexType)以及复杂类型的简单操作. 通常,复杂类型是指那些由几个简单的类型组合而成的类型.比如:一张Customer表,其中有FristName和Las ...
- Entity Framework 5.0系列之EF概览-三种编程方式
概述 在开发面向数据的软件时我们常常为了解决业务问题实体.关系和逻辑构建模型而费尽心机,ORM的产生为我们提供了一种优雅的解决方案.ADO.NET Entity Framework是.NET开发中一种 ...
- Entity Framework入门教程(2)---EF工作流程
EF工作流程 1.EF基本CRUD流程 下边的图就可以很清晰地展示EF的CRUD操作的基本工作流程: 这里做一个EF CRUD操作的简单总结:1.定义模型:这是EF工作的前提,定义模型包括定义领域类( ...
- Entity Framework入门教程(3)---EF中的上下文简介
1.DbContext(上下文类) 在DbFirst模式中,我们添加一个EDM(Entity Data Model)后会自动生成一个.edmx文件,这个文件中包含一个继承DbContext类的上下文实 ...
- Entity Framework入门教程(4)---EF中的实体关系
这一节将总结EF是怎么管理实体之间的关系.EF与数据库一样支持三种关系类型:①一对一 ,②一对多,③多对多. 下边是一个SchoolDB数据库的实体数据模型,图中包含所有的实体和各个实体间的关系.通过 ...
- Entity Framework入门教程(5)---EF中的持久化场景
EF中的持久性场景 使用EF实现实体持久化(保存)到数据库有两种情况:在线场景和离线场景. 1.在线场景 在线场景中,context是同一个上下文实例(从DbContext派生),检索和保存实体都通过 ...
随机推荐
- Django Cookie和Seesion
1.cookie不属于http协议范围,由于http协议无法保持状态,但实际情况,我们却又需要“保持状态”,因此cookie就是在这样一个场景下诞生.cookie的工作原理是:由服务器产生内容,浏览器 ...
- 45_redux_comment应用_redux版本_异步功能
/* * 包含所有action的type名称常量 * */ //添加评论 export const ADD_COMMENT = 'add_comment'; //删除评论 export const D ...
- 批处理BAT运行不显示DOS窗口的方法
新建记事本,写入下面内容 set ws=wscript.createobject("wscript.shell") ws.run "D:\scripts\svn-upda ...
- js:苹果手机页面返回,数据不刷新问题
$(function () { var isPageHide = false; window.addEventListener('pageshow', function () { ...
- ensureCapacity增加此 ArrayList 实例的容量,以确保它至少能够容纳最小容量参数所指定的元素数。
扩容原则: 若参数值大于底层数组长度的1.5倍,则数组的长度就扩容为这个参数值:若小于底层数组长度的1.5倍,则数组长度就扩容为底层数组长度的1.5倍. ensureCapacity提高效率 fina ...
- [Linux] umask 从三类人群的权限中拿走权限数字
作用 umask 用来设置用户创建文件.目录的默认权限,通过从权限中拿走相应的位,格式 `umask nnn`. 理解 rwx rwx rwx 权限对应三类人群,所属人,所属组,其 ...
- week05 codelab01 Babel ES6 webpack Nodejsserver等
Babel 他出现的原因就是很多浏览器还未完全兼容ES6 需要将你写的ES6的内容转换成ES5让浏览器兼容运行 ES5和ES6相比出现很多新内容 比如拼接字符串 ES6可以` ` 里面如果引用变量就用 ...
- JASPER打印单据,标签开发培训, 界面开发培训
JASPER打印单据,标签开发培训软件:TIBC JASPER Studio.Jaspersoft Studio是一个专为JasperReports报表引擎而开发的报表设计器,是 iReport设计器 ...
- Python学习—数据库篇之初识mysql
一.下载与安装 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是最好 ...
- VS 提示对象被多次指定;已忽略多余的指定
最近有一个工程编译老是出现这个问题,网上的解决方案说是工程目录下有同名的源文件,所以编译出了同名的obj.然而我检查了一下并没有.经尝试,把所有文件从项目中移除再重新添加进来就行了..应该是因为我反复 ...


