当前位置:网站首页>Introduction to ef framework
Introduction to ef framework
2022-07-27 18:08:00 【Charmaine Xia】
EF The full name is EntityFramework .
Entity Framework yes ADO.NET A set of technologies to support the development of data oriented software applications , It's one of Microsoft's ORM frame .
ORM frame (Object Relational Mapping) Translated as object relational mapping .
Two 、EF Entity Framework overall architecture :

Architecture components :
EDM( Entity data model ): EDM It's made up of three main parts - conceptual model , Map and store models .
Conceptual Model: Conceptual models contain model classes and their relationships . This will be independent of your database table design .
Storage Model: The storage model includes tables , View , Database design model of stored procedure and its relationship and key .
Mapping: The mapping consists of information about how the conceptual model maps to the storage model .
LINQ to Entities: LINQ to Entities Is a query language for writing queries against object models . It returns the entities defined in the conceptual model . You can use your... Here LINQ Skill .
Entity SQL: Entity SQL Is another query language ( Only applicable to EF 6), It's like LINQ to Entities equally . However , This is more than L2E It's a little harder , Developers need to learn alone .
ObjectServices: Object service is the main entry point to access the data in the database and return it . Object services are responsible for implementing , This will be from the entity client data provider ( The next layer ) The process of converting the returned data into an entity object structure .
Entity Client Data Provider: The main responsibility of this layer is to LINQ-to-Entities Or entity SQL The query is transformed into something that the underlying database can understand SQL Inquire about . It is associated with ADO.Net Data provider communication , and ADO.Net The data provider sends or retrieves data from the database .
ADO.Net Data Provider: This layer uses standard ADO.Net Communicating with the database .
3、 ... and 、EF The advantages of ( And Comparison of )
If not ORM frame , We usually use it like this ADO.NET Database development :
1. take ADO.NET The operations on the database are encapsulated in a class SqlHelper in
2. stay DAL Layer calls SqlHelper
3. Other layers call DAL Perform database operations
1.【 Logic 】 Business logic and data access logic are separated ;
2.【 New operation 】 EF: One connection , Execute more than one sql;SqlHelper Use general writing in , The connection cannot be released , use using, It will cause multiple connection resets ;
3.【 update operation 】 EF Automatic optimization , only update set Changing fields ,EF You can also easily update only Specified attributes of entities , Produced sql In the sentence set There will be fewer fields after ;
4.【 Smart tips 】 use linq, lamda expression There are smart tips , Wrong writing, but ; Write sql Statement string , transfer sqlhelper,sql If the statement is written incorrectly, it will be compiled and passed ;
5.【 Security 】 No prevention sql The trouble of injection ;
6.【 Database changes 】 Use EF, Switching is convenient ;
7.【 efficiency 】 Use EF Compared to using Ado.net High development efficiency ;
8.【 Readability 】 The code is more readable .
Four 、EF Three modes of framework

Database First( Database first )
If you already have a database ,Visual Studio The built-in Entity Framework The designer can automatically generate a data model , The model consists of objects corresponding to existing databases ( See table and column ) Classes and properties of . About database structure , The information between the data model and the mapping is in XML The format is stored in .edmx In file . Entity Framework designer provides a visual interface , You can use it to display and edit .edmx file .
Model First( Model first )
If you don't have a database , You can use Visual Studio Medium Entity Framework The designer is in .edmx Create a model in the file . When the model is finished , It can be executed .edmx File to create a database .
Code First( Code first )
Whether you have a database or not , You can use Code First. If there is no database , You can write classes and properties corresponding to tables and columns . If there is a database , that Entity Framework You can generate classes and attributes corresponding to existing tables and columns . If you use Code First Create database , You can use “migration( transfer )” To deploy the database to the production environment . When the data model changes , Changes can be deployed to the production environment , Without changing the original data
边栏推荐
- 类的六大关系——依赖和关联的区别
- Soul 1: why is es more suitable for complex condition search than MySQL?
- Behind every piece of information you collect, you can't live without TA
- 知物由学 | 易盾移动端同构实践,几步改善官网交互体验
- [introduction to database system (Wang Shan)] Chapter 1 - Introduction
- Using the vlookup method in salesforce validation rule
- 卷积神经网络——YOLOV2(YOLO9000)论文翻译
- Learn from things | Yidun mobile terminal isomorphism practice, improve the official website interaction experience in a few steps
- golang 自定义once,当出现error第二次重新设置
- Knowing things by learning | app slimming down, the way of safety reinforcement under the new generation AAB framework
猜你喜欢

Learn from what you know | Yidun self-developed text real-time clustering technology, and wipe out the same kind of harmful content in social networks

最新大厂高级面试题 必备

numpy数组矩阵操作

Code compliance: five reasons why developers use helix QAC

JSP custom tag (bottom)

Cow! His secret is to reproduce the paper in 2 hours——

How to develop an online Excel spreadsheet system (Part 1)

如何限制root远程登入,使普通用户拥有root权限

【Codeforces】 A. Computer Game

Evaluation index of machine learning (I) -- regression evaluation index
随机推荐
ES查询限制10000条数据解决方法
JDBC connection database reading foreground cannot display data
知物由学 | 再造巴别塔,我们如何进行NLP跨语言知识迁移?
多线程实现循环
Wechat applet to make calls
Evaluation index of machine learning (I) -- regression evaluation index
Knowledge dry goods: basic storage service novice Experience Camp
[Southwest University] information sharing of postgraduate entrance examination and re examination
js工具-cookie简单封装
知物由学 | 小游戏的安全风险在哪里?
WebDriverException( selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executabl
[introduction to database system (Wang Shan)] Chapter 4 - Database Security
js实现页面或DOM元素平滑滚动
Knowing things by learning | app slimming down, the way of safety reinforcement under the new generation AAB framework
Salesforce File Share and Security
Could not obtain transaction-synchronized Session for current thread
PostgreSQL 14 支持winserver2022吗?
Telecommuting can be easily realized in only three steps
微信小程序 云函数批量删除多条数据 Error: errCode: -502005 database collection not exists
Compilation and testing of raspberry pie driver code