I am converting a classic ASP website to .NET. The application already has a back-end database with stored procedures for communicating with the DB. I want to use MVC3 and EF for this project.
My question is where is a good moderate example of these working in this environment?
I understand how the Model View Controller pattern works on basic examples. I went through the MVC Music Store demo and deployed it. However, I’m struggling with where I put certain code.
I’m looking for examples of how to tie into the existing DB with EF using the stored procedures and how the models should look. I’m also looking for where do I put code which is traditionally object methods.
If I have a Contact model, where does the code go to interact with that contact? And I’m not talking about the code that brings back the data you want to push to the View. Is that where Repositories come in? If so, where is a good tutorial on using repositories?
I appreciate the help. I realize this is a bunch of questions in one, but I don’t think I’m the only one struggling with this either.
I would definitely put the
DALin a separate project and I would definitely create an abstraction layer between the data access layer and the business logic layer of my application.The Repository and Unit of Work Patterns are great for this purpose.
You can take a look at following articles. They are great for starting to create your data access layer :
Creating an Entity Framework Data Model for an ASP.NET MVC Application
http://www.asp.net/entity-framework/tutorials/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
Implementing the Repository and Unit of Work Patterns in an ASP.NET MVC Application
http://www.asp.net/entity-framework/tutorials/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
These are from Getting Started with EF using MVC series on http://asp.net. You can find more useful articles there from the navigation panel on the left hand site there.