Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data Access in ASP.NET MVC 3

What's the recommended way of creating a Data Access layer in real-life ASP.NET MVC applications? Is it EF? Ef Code First? NHibernate? Any other idea?

Thank you & regards

like image 460
Bill Avatar asked Jan 23 '26 06:01

Bill


2 Answers

There is no recommend way.

I prefer EF Code First for doing this because

  • the Sourcecode is very clean and easy to read
  • It is easy to simple change the connectionstring and generate a new database if not already exists
  • easy to migrate your Database if your Model has changed (no need to recreate the Database) using EntityFramework.SqlMigrations
  • if your Database already exists you can use the Entity Framework Power Tools to generate the Models and Database context from your existing Database
like image 196
dknaack Avatar answered Jan 25 '26 20:01

dknaack


It all depends of your need:

  • NHibernate is a more mature ORM with a big community

  • Entity Framework is now getting very well supported and you can find also great information (check Julie Lerman blog)

Both support code generation from database.

Code first: allows you to create your database schema from your domain models. This is great if you don't want to bother with database. NHibernate can do it also.

To help you decide which way to use Entity Framework

enter image description here

Source

There are many other great ORM:

Subsonic

Stackoverflow's ORM Dapper if performance is an important criteria there is a small benchmark on the site

like image 36
JuChom Avatar answered Jan 25 '26 22:01

JuChom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!