user1626577
user1626577

Reputation: 3

Best Practice for handling database CRUD functionality ASP.net MVC3

I have project to develop marketplace on MVC 3 and I myself learning the MVC from ASP.net/MVC

In the tutorials and samples I learned to use database CRUD functionalities can be done using EF with ease by defining properties in model and creation of Model entities.

I recently hired a programmer to code on the project. He suggested method for database CRUD functionality by writing SQL statements like we did for web forms by defining datamodels. He said using the prescribed method in MVCMusicStore will create problem later like if any other programmer will make changes in Model property it will update the database and can have issues.

I dont have idea regarding best practice on large project for database interaction Using MVC.

Upvotes: 0

Views: 1440

Answers (3)

Shyju
Shyju

Reputation: 218732

ASP.NET MVC is not tied up with Entity Framework. Inded MVC does not care about what is the Data Access method you are using. MVC is a framework to develop web apps. It does not worry about the Data Access method. You can use Entity framework / LinqToSQL / NHinernate/ADO.NET etc..

The sample projects out there usually uses the Model classes (your domain model) in the view. But when you start writing code for a project, you will understand the need of seperating the Model from being used in Views and Creating seperate POCO classes for these Views. We call it as ViewModels. We map these ViewModels to Domain models in between. This gives us more flexibility. But keep in mind that it is not necessary to have ViewModels for every model. Create those as necessary only.

Look into the Repositary pattern. Have your Data Access method there. The implementation of these data access method can be using any data access methods (LINQ / EF etc...). The Advantage of using EF is that, you do not need to write a lot of code your self.

Upvotes: 1

AndyC
AndyC

Reputation: 1335

You should look into Entity Framework Code First. Check out this blog post by Scott Gu about Code first with Entity Framework: http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

Code first supports changing the model without have to completly redo the database.

Upvotes: 0

Thiago Custodio
Thiago Custodio

Reputation: 18387

I like EF Code First feature. It's a very good feature when you have teams working in different parts of the system. You don't need to drop and recreate all database everytime. Take a look at this article for more information about EF initializers: http://www.codeguru.com/csharp/article.php/c19999/Understanding-Database-Initializers-in-Entity-Framework-Code-First.htm

Upvotes: 0

Related Questions