Bill
Bill

Reputation: 2352

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

Upvotes: 2

Views: 1211

Answers (7)

JuChom
JuChom

Reputation: 5989

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

Upvotes: 3

dknaack
dknaack

Reputation: 60448

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

Upvotes: 4

undefined
undefined

Reputation: 34238

The MVC gurus (the people who wrote MVC) at MS all seem to use Entity Framework at the moment. having said that you can use any ORM (or really any data access tech you want) as MVC doesnt actually specify anything at all about the way you access data

Upvotes: 0

Keith Nicholas
Keith Nicholas

Reputation: 44288

There is none, stackoverflow is full of people who have gone down the various routes, so you can get help no matter which choice you make.

Best advice, try doing a few small exploratory webs using a couple of approaches which seem to stand out.

Upvotes: 1

Travis J
Travis J

Reputation: 82267

I like to use Model First because it allows me the most freedom to design and implement in my opinion. It also makes it very easy to change the database design.

Upvotes: 1

RyanW
RyanW

Reputation: 5398

If you're partial to the MSFT tooling and wanting to be "modern", then EF Code First is probably the place to start. One example worth perusing: https://github.com/NuGet/NuGetGallery .

Upvotes: 1

Kshitij Banerjee
Kshitij Banerjee

Reputation: 1748

Try LINQ, most MVC products I see make use of LINQ.

Upvotes: -1

Related Questions