In an MVC application, where should the Entity Framework Data Model be placed?

asp.net-mvc asp.net-mvc-2 design-patterns entity-framework

Question

Let's look at the default folder structure for an ASP.NET MVC application, which is as follows:

-App_data
-Content
-Controllers
    HomeController.cs
-Models
    AccountModels.cs
-Scripts
-Views

Where is the ideal location to store the Entity Framework Data Model (EDMX) file, I wonder? Is it the Models folder? Yes, we are aware that a decent approach is to create a new project and refer to it in the MVC application, but let's ignore this for the time being.

1
14
1/16/2011 10:16:08 PM

Accepted Answer

It ought to be a component of the Model for a little project. The repository and its accompanying model may be in a different assembly for a bigger product.

18
1/16/2011 10:19:12 PM

Popular Answer

It's questionable, but I'd give the Models folder a +1.

The only other option would be App_Data, but it is usually reserved for file-based databases (like SQL Server CE.MDF) and files that you don't want IIS to serve.

The EDMX belongs in the Models folder since it is a abstraction of the database.

You should definitely migrate your EF Model into another project if the project expands. Make your Controllers access the EDMX via Repository/Interfaces to avoid this in the future. That way, all you'll need to do to transfer the DAL to a new project is add the reference and the using lines.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow