当前位置:网站首页>EF框架简介
EF框架简介
2022-07-27 15:55:00 【夏诗曼CharmaineXia】
EF 全称是 EntityFramework 。
Entity Framework是ADO.NET 中的一套支持开发面向数据的软件应用程序的技术,是微软的一个ORM框架。
ORM框架(Object Relational Mapping) 翻译过来就是对象关系映射。
二、EF实体框架整体架构:

架构组件:
EDM(实体数据模型): EDM由三个主要部分组成 - 概念模型,映射和存储模型。
Conceptual Model:概念模型包含模型类及其关系。这将独立于您的数据库表设计。
Storage Model:存储模型是包括表,视图,存储过程及其关系和密钥的数据库设计模型。
Mapping:映射由有关概念模型如何映射到存储模型的信息组成。
LINQ to Entities: LINQ to Entities是一种用于针对对象模型编写查询的查询语言。它返回在概念模型中定义的实体。你可以在这里使用你的LINQ技能。
Entity SQL:实体SQL是另一种查询语言(仅适用于EF 6),就像LINQ to Entities一样。然而,这比L2E稍微难一些,开发者需要单独学习。
ObjectServices:对象服务是访问数据库中的数据并将其返回的主要入口点。对象服务负责实现,这是将从实体客户端数据提供者(下一层)返回的数据转换为实体对象结构的过程。
Entity Client Data Provider:此层的主要职责是将LINQ-to-Entities或实体SQL查询转换为底层数据库可以理解的SQL查询。它与ADO.Net数据提供者通信,而ADO.Net数据提供者又从数据库发送或检索数据。
ADO.Net Data Provider:该层使用标准的ADO.Net与数据库进行通信。
三、EF 的优势(与 的对比)
如果不用ORM框架,我们一般这样来使用ADO.NET进行数据库开发:
1.将ADO.NET对数据库的操作封装到一个类里SqlHelper中
2.在DAL层调用SqlHelper
3.其他层再调用DAL进行数据库操作
1.【逻辑】业务逻辑和数据存取逻辑分离开来;
2.【新增操作】 EF:一次连接,执行多条sql;SqlHelper里使用一般写法,连接又无法释放,用using,会造成多次连接重置;
3.【更新操作】 EF自动优化,只update set 有变化的字段,EF也可以很方便地只更新 实体的指定属性,产生的sql语句里的set后的字段会更少;
4.【智能提示】 用linq, lamda表达式 有智能提示,写错了编译不过;写sql语句字符串,调sqlhelper,sql语句写错一样编译通过;
5.【安全】 省去了防止sql注入的麻烦;
6.【数据库变更】使用EF,切换较方便;
7.【效率】 使用EF要比使用Ado.net开发效率高;
8.【可读性】 代码的可读性更高.
四、EF框架的三种模式

Database First(数据库优先)
如果已经拥有数据库,Visual Studio中内置的Entity Framework设计器可以自动生成一个数据模型,该模型由对应于现有数据库对象(如表和列)的类和属性组成。有关数据库结构,数据模型及映射之间的信息以XML格式存储在.edmx文件中。实体框架设计器提供了一个可视化界面,您可以使用它来显示和编辑.edmx文件。
Model First(模型优先)
如果您还没有数据库,则可以使用Visual Studio中的Entity Framework设计器在.edmx文件中创建一个模型。当模型建完后,可以执行.edmx文件来创建数据库。
Code First(代码优先)
无论您是否拥有数据库,都可以使用Code First。如果没有数据库,可以编写类和对应于表和列的属性。如果有数据库,那么Entity Framework可以生成与现有表和列对应的类和属性。如果使用Code First创建数据库,则可以使用“migration(迁移)”来将数据库部署到生产环境。当数据模型更改时,可以将更改部署到生产环境中,而不改变原有的数据
边栏推荐
- 美团到餐“祖传数仓”标准化治理笔记
- 机器学习之评价指标(二)——分类评价指标
- 微信小程序 实现位置地图显示,引入map地图,不含导航
- 机器学习之评价指标(一)——回归评价指标
- 6月第1周易盾业务风控关注 | 新东方学而思等15家机构被顶格罚款
- C语言怎么学?这篇文章给你完整答案
- Know things by learning | build a real-time anti plug-in mechanism from 0 to 1 to supplement the offensive and defensive power of mobile games in multiple dimensions
- hutool 字符串工具类
- Numpy array matrix operation
- Operation of simulated examination platform for 2022 low voltage electrician examination questions
猜你喜欢
知物由学 | SO加固如何提升Android应用的安全性?

What should we pay attention to when choosing the LED display screen of the stadium

Functions of C language

MySQL view and stored procedure

Learn from things | Yidun mobile terminal isomorphism practice, improve the official website interaction experience in a few steps

知物由学 | 易盾自研文本实时聚类技术,一网打尽社交网络中的同类有害内容

An end-to-end file upload program based on form, including client and server

Count the six weapons of the domestic interface cooperation platform!

Convolutional neural network -- Introduction to FPN (feature pyramid networks)

How difficult the interview is! I was forced to survive the six rounds of interview of ant financial! Almost out (interview resumption)
随机推荐
Knowledge dry goods: basic storage service novice Experience Camp
Mysql database defines cursor in trigger
How difficult the interview is! I was forced to survive the six rounds of interview of ant financial! Almost out (interview resumption)
JDBC连接数据库读取前台无法显示数据
golang worker池
Does PostgreSQL 14 support winserver2022?
@Scheduled 和Quartz
Yanrong technology was selected as Beijing's "specialized and innovative" in 2022 to lead hybrid cloud file storage
JS to realize the right-click menu bar function
MySQL view and stored procedure
js实现右键菜单栏功能
numpy数组矩阵操作
Fast parsing combined with Huatu document encryption software
细数国产接口协作平台的六把武器!
Numpy array matrix operation
[introduction to database system (Wang Shan)] Chapter 5 - database integrity
Are those who are absent from the written examination shortlisted for the teacher recruitment interview? Henan Xiangfu: the statistics of individual candidates' scores are wrong
How can we carry out NLP cross language knowledge transfer?
In the first week of June, risk control of e-shield business paid attention to 15 institutions such as New Oriental XRS, which were fined
I got the P8 "top-level" distributed architecture manual crazy spread on Alibaba intranet