Entity Framework VS pure Ado.Net

前端 未结 4 732
难免孤独
难免孤独 2020-12-04 18:16

EF is so widely used staff but I don\'t realize how I should use it. I met a lot of issues with EF on different projects with different approaches. So some questions brought

相关标签:
4条回答
  • 2020-12-04 18:30

    ADO.NET provides consistent access to data sources such as SQL Server and XML, and to data sources exposed through OLE DB and ODBC. Data-sharing consumer applications can use ADO.NET to connect to these data sources and retrieve, handle, and update the data that they contain.

    Entity Framework 6 (EF6) is a tried and tested object-relational mapper (O/RM) for .NET with many years of feature development and stabilization. An ORM like EF has the following advantage

    • ORM lets developers focus on the business logic of the application thereby facilitating huge reduction in code.

    • It eliminates the need for repetitive SQL code and provides many benefits to development speed.

    • Prevents writing manual SQL queries; & many more..

    1. In an n-tier application,it depends on the amount of data your application is handling and your database is managing. According to my knowledge DTO's don't kill performance. They are data container for moving data between layers and are only used to pass data and does not contain any business logic. They are mostly used in service classes.See DTO.
    2. One DBContext is always a best practice.
    3. There is no such combination of EF + SP(Stored Procedure) as per my knowledge. If you wish to use an ORM like EF and an SP at the same time try micro-ORMs like Dapper,BLToolkit, etc..It was build for that purpose and is heck lotta fast than EF. Here is a good article on Dapper ORM.

    Here is a related thread on a similar topic: What is the difference between an orm and ADO.net?

    0 讨论(0)
  • 2020-12-04 18:33

    By following the naming conventions , you will find it's called : ADO.NET Entity Framework , which means that Entity Framework sits on top of ADO.NET so it can't be faster , It may perform both in equal time , but let's look at EF provides :

    • You will no more get stuck with writing queries without any clue about if what you're writing is going to compile or not .
    • It makes you rely on C# or your favorite .NET language on writing your own data constraints that you wish to accept from the target user directly inside your model classes .

    Finally : EF and LINQ give a lot of power in maintaining your applications later .

    There are three different models with the Entity Framework : Model First , Database First and Code First get to know each of 'em .

    -The Point about killing performance when remapping is on process , it's because that on the first run , EF loads metadata into memory and that takes time as it builds in-memory representation of model from edmx file.

    0 讨论(0)
  • 2020-12-04 18:36

    Entity Framework is not efficient in any case as in most tools or toolboxes designed to achieve 'faster' results.

    1. Access to database should be viewed as a separate tier using store procedures as the interface. There is no reason for any application to have more than absolutely require CRUD operations. Less is more principle. Stored procedures are easy to write, secure, maintain and is de facto fastest way. It's easy to write tools to generate desired codes for POCO and DbContext through stored procedures.

    2. Application well designed should have a limited numbers of connection strings to database and none of which should be the all mighty God. Using schema to support connection rights.

    3. Lazy loading are false statements added to solve a problem that should never exist and introduced with ORM and its plug and play features. Data should only be read when needed. Developers should be responsible to implement this logic base on application context.

    4. If your application logic has a problem to maintain states, no tool will help. It will in fact, make it worse by cover up the real problem until it's too late.

    5. Database first is the only solution for a well designed application. Civilization realized long time ago the important of solid aqueduct and sewer system. High level code can and will be replaced anytime but data stays. Rewrite an entire application is matter of days if database is well designed.

    6. Applications are just glorified database access. Still true in most cases.

    This is my conclusion after many years in business applications debugging through codes produced by many different tools or toolboxes. The faster results advertised are not even close to cover the amount of time/energy wasted later trying to clean up the mess. Performance issues are rarely if not ever caused by high demand but the sum of all 'features' added through unusable tools.

    0 讨论(0)
  • 2020-12-04 18:38

    ADO. Net is an object oriented framework that allows you to interact with database system (SQL, Oracle, etc). Entity framework is a techniques of manipulating data in databases like (collection of queries (inert table name , select * from like this )). it is uses with LINQ.

    0 讨论(0)
提交回复
热议问题