EntityFramework VS pure Ado.Net

ado.net c# entity-framework linq stored-procedures

Question

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 together in my head. And answers leads me to use pure ado.net with stored procedures. So the questions are:

  1. How to deal with EF in n-tier application? For example, we have some DAL with EF. I saw a lot of articles and projects that used repository, unitofwork patterns as some kind of abstraction for EF. I think such approach kills most of benefits that increase development speed and leads to few things:
    • remapping of EF load results in some DTO that kills performance(call some select to get table data - first loop, second loop - map results to some composite type generated by ef, next - filter mapped data using linq and, at last, map it to some DTO). Exactly remapping to DTO is killer of one of the biggest efs benefit;
      or
    • leads to strong cohesions between EF (and it's version) and app. It will be something like 2-tier app with dal and presentation with bll or dal with bll and presentation. I guess it's not best practice. And the same loading process as we have for previous thing except mapping, so again performance issue raised up. We could try to use EF as DAL without any abstraction under them. But we will get similar issues in some other way.
  2. Should I use one context per app\thread\atomic operation? Using approach - one context per app\thread may slightly increase performance and possibilities to call navigation properties, but we meet another problem - updating this context and growing loaded data in context, also I'm not sure about concurrency with one dbcontext per app\thread. Using context per operation will lead us to remapping ef results to our DTO's. So you see that we again pushed back to question no.1.

  3. Could we try to use EF + SP's only? Again we have issues from previous questions. What is the reason to use ef if the biggest part of functionality will not be used?

So, yes EF is great to start project. It so convenient when we have few screens and crud operations. But what next?

All this text is just unsorted thoughts. I know that pure ado.net will lead to another kind of challenges. So, what is your opinion about this topic?

1
31
3/11/2014 2:35:47 PM

Accepted Answer

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.

20
3/11/2014 3:17:44 PM

Popular Answer

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?



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow