Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ADO.NET Entity Framework or ADO.NET

I'm starting a new project based on ASP.NET and Windows server.

The application is planned to be pretty big and serve large amount of clients pulling and updating high freq. changing data.

I have previously created projects with Linq-To-Sql or with Ado.Net.

My plan for this project is to use VS2010 and the new EF4 framework.

  • It would be great to hear other programmers options about development with Entity Framework

  • Pros and cons from previous experience?

  • Do you think EF4 is ready for production?

  • Should i take the risk or just stick with plain old good ADO.NET?
like image 653
RuSh Avatar asked Mar 14 '10 23:03

RuSh


People also ask

Should I use ADO.NET or Entity Framework?

If we want to achieve more control over SQL commands and operations with the help of raw SQL Queries, then ADO.NET will be a great choice to start work with. Whereas if we want to develop the application in a much faster way with clear code maintainability, then Entity Framework will be the better choice.

What is faster ADO.NET or ado net entity framework?

The performance of ADO.Net is better than entity framework because ADO.Net is directly connected to the data source due to that it gives better performance than entity framework, whereas the performance of entity framework is less as compared to the ADO.Net as entity translate the LINQ queries to SQL first and then ...

Can we use ADO.NET and Entity Framework together?

EF is built on top of ADO.Net, meaning that you can use both at the same time.


2 Answers

Whether EF4 is really ready for production is a bit hard to say since it's not officially been released yet.... but all the preliminary experiences and reports about it seem to indicate it's quite good.

However: you need to take into consideration what EF is trying to solve; it's a two-layer approach, one layer maps to your physical storage schema in your database (and supports multiple backends), and the second layer is your conceptual model you program against. And of course, there's the need for a mapping between those two layers.

So EF4 is great if you have a large number of tables, if you have multiple backends to support, if you need to be able to map a physical schema to a different conceptual schema, and so forth. It's great for complex enterprise level applications.

BUT that comes at a cost - those extra layers do have an impact on performance, complexity, maintainability. If you need those features, you'll be happy to pay that price, no question. But do you need that??

Sure, you could go back to straight ADO.NET - but do you really want to fiddle around with DataTables, DataRows, and untyped Row["RowName"] constructs again?? REALLY???

So my recommendation would be this:

  • if you need only SQL Server as your backend
  • if you have a fairly simple and straightforward mapping of one database table to one entity object in your model

then: use Linq-to-SQL ! Why not?? It's still totally supported by Microsoft in .NET 4 - heck, they even did bugfixes and added a few bits and pieces - it's fast, it's efficient, it's lean and mean - so why not??

like image 54
marc_s Avatar answered Sep 22 '22 11:09

marc_s


My advice is use both. At first I thought I would only use linq to sql and never have to touch ado.net ever again ( what made me happy lol).

Now I am using both because some things linq to sql(and any ORM like EF) can't do. I had to do some mass inserts and I did it first with linq to sql and to do 500 records it took over 6mins(2 mins for validation rules rest was inserting into the db).

I changed it to sql bulk copy and now it is down to 2min and 4 seconds(4 seconds to do all inserts)

But like marc_s said I really did not want to fiddle around with DataTables, DataRows, and untyped Row["RowName"].

Say my table was like 10 columns long and called Table A. What I did was I used linq to sql and made a Table A class( new TableA()) object and populated it with data. I then would pass this object to a method that created the datarow.

So linq to sql saved me some time because I probably would have made a class as I would not have wanted to pass in 10 parameters into the method that makes the data row. I also feel it gives a bit of typeness back as you have to pass in the right object to use that method so less chance of passing in the wrong data.

Finally you can still use linq to sql to call Stored procedures and that is like one line of code.

So I would use both when ever you notice that linq to sql (or in your case EF) is slow then just write a SP and call it through EF. If you need to do straight ado.net evaluate what you need to do maybe you can use EF for most of the code(so you can at least work with objects) and only for that small portion ado.net sort of what I did with sql bulk copy.

like image 40
chobo2 Avatar answered Sep 24 '22 11:09

chobo2