一定要用Entity Framework吗?

答案

是不一定,即不一定要用EF;

如果你是一个接触编程的时候,就是通过ef进行Database数据持久化的人来说,你就用ef,因为你对ef的一切都是感觉很自然的;

而你是从ado,ado.net一路走过来的人,真的不一定要用EF;而且EF还是建立在ADO.net之上的框架,为什么我们要舍本逐末呢?

 

EF是什么?有什么用?为什么要用EF?

Entity Framework Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations. EF Core works with many databasees, including SQL Database (on-premises and Azure), SQLite, MySQL, PostgreSQL, and Azure Cosmos DB.(https://docs.microsoft.com/en-us/ef/


下面来自于:https://www.tutorialspoint.com/entity_framework/entity_framework_overview.htm

What is Entity Framework?

Entity Framework was first released in 2008, Microsoft's primary means of interacting between .NET applications and relational databases. Entity Framework is an Object Relational Mapper (ORM) which is a type of tool that simplifies mapping between objects in your software to the tables and columns of a relational database.

  • Entity Framework (EF) is an open source ORM framework for ADO.NET which is a part of .NET Framework.

  • An ORM takes care of creating database connections and executing commands, as well as taking query results and automatically materializing those results as your application objects.

  • An ORM also helps to keep track of changes to those objects, and when instructed, it will also persist those changes back to the database for you.

Why Entity Framework?

Entity Framework is an ORM and ORMs are aimed to increase the developer’s productivity by reducing the redundant task of persisting the data used in the applications.

  • Entity Framework can generate the necessary database commands for reading or writing data in the database and execute them for you.

  • If you're querying, you can express your queries against your domain objects using LINQ to entities.

  • Entity Framework will execute the relevant query in the database and then materialize results into instances of your domain objects for you to work within your app.

There are other ORMs in the marketplace such as NHibernate and LLBLGen Pro. Most ORMs typically map domain types directly to the database schema.

Typical ORM

Entity Framework has a more granular mapping layer so you can customize mappings, for example, by mapping the single entity to multiple database tables or even multiple entities to a single table.

EF Runtime Metadata

  • Entity Framework is Microsoft's recommended data access technology for new applications.

  • ADO.NET seems to refer directly to the technology for data sets and data tables.

  • Entity Framework is where all of the forward moving investment is being made, which has been the case for a number of years already.

  • Microsoft recommends that you use Entity Framework over ADO.NET or LINQ to SQL for all new development.

Conceptual Model

For developers who are used to database focused development, the biggest shift with Entity Framework is that it lets you focus on your business domain. What it is that you want your application to do without being limited by what the database is able to do?

  • With Entity Framework, the focal point is referred to as a conceptual model. It's a model of the objects in your application, not a model of the database you use to persist your application data.

  • Your conceptual model may happen to align with your database schema or it may be quite different.

  • You can use a Visual Designer to define your conceptual model, which can then generate the classes you will ultimately use in your application.

  • You can just define your classes and use a feature of Entity Framework called Code First. And then Entity Framework will comprehend the conceptual model.

Conceptual Model

Either way, Entity Framework works out how to move from your conceptual model to your database. So, you can query against your conceptual model objects and work directly with them.

Features

Following are the basic features of Entity Framework. This list is created based on the most notable features and also from frequently asked questions about Entity Framework.

  • Entity Framework is a Microsoft tool.
  • Entity Framework is being developed as an Open Source product.
  • Entity Framework is no longer tied or dependent to the .NET release cycle.
  • Works with any relational database with valid Entity Framework provider.
  • SQL command generation from LINQ to Entities.
  • Entity Framework will create parameterized queries.
  • Tracks changes to in-memory objects.
  • Allows to insert, update and delete command generation.
  • Works with a visual model or with your own classes.
  • Entity Framework has stored Procedure Support.

下面来自:https://www.got-it.ai/solutions/sqlquerychat/sql-help/general-sql/clarifying-the-confusion-between-ado-net-entity-framework-and-linq-querychat/

Entity Framework (or ADO.NET Entity Framework)

Entity Framework is the Microsoft version of Object-Relational Mapper (ORM). It’s important to note that Entity Framework is built on ADO.NET classes. Entity Framework is also called ADO.NET Entity Framework.

As developers work with strongly typed .NET objects called entities, there was a big gap between the object models used in the Object-Oriented Programming (OOP) and the data storage, which is in a relational model. Much code was needed to deal with this gap. ORM was created to resolve this issue. It is a technique for converting data stored in a relational database to domain-specific classes. 

Entity Framework offers many benefits compared to previous technology. One of its advantages is the excellent tooling support where we can build and maintain data access in a much shorter time. We can focus on solving business problems without worrying about the underlying data storage. 


下面来自:https://www.cnblogs.com/weixb/p/9640089.html

为什么要使用Entity Framework

本文介绍从DDD(Domain-Driven Design[领域驱动设计])的角度来说说为什么要使用Entity Framework(以下都会简称为EF),同时也看出类似Drapper之类的简陋ORM不足的地方。


使用EF我们要注意的是什么?

下面来自:https://www.iamtimcorey.com/blog/137806/entity-framework

  1. Does your team understand how to use Entity Framework well?
  2. Does your team know how to diagnose issues with Entity Framework code?
  3. Does your team know how to diagnose under-performing EF queries and fix them?
  4. Does your team understand the code that EF wrote for you well enough to know what it is doing?
  5. Does your team know how to protect the EF credentials on client machines?

也有反馈使用了EF,后面又回退回ADO.net的,如下面的文章:

https://cerkit.com/2018/10/28/why-we-decided-to-stop-using-entity-framework-and-go-back-to-ado-net/

After a few weeks of analysis, we decided that going backwards in time to a somewhat less civilized time would be the answer. We decided to stop using Entity Framework and use "raw" ADO.NET to access stored procedures mapped to DTOs. We weren't comfortable having our queries compiled into the language as LINQ expressions. Keeping them in the database as stored procedures would keep our options free for the future when C# and .NET are no longer the coolness.


真的一定要用EF吗?

如果只是为了ORM(object- relational mapping),我们真的需要EF吗?使用Dapper不行吗?也许Dapper不是一个很彻底的ORM,但是这个不重要,我们想要的只是想让数据库中数据和应用程序中对象能够快速进行转换就好了,其他像什么keep trace等,要他做什么?保存,持久化的逻辑,我都是自己做的,为什么要用它?所以这样看来,可能我使用auto mapper都能完成我的要求,真的不一定要用ef,如此庞大,如此复杂,出现问题不知道那里出了问题,不是自己找麻烦吗。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值