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

Lets consider default ASP.NET MVC application folder structure, so it's looks like this:

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

My question is: Where is the best place to put Entity Framework Data Model (EDMX) file? Is it Models folder? Yes - we know that good solution is to introduce new Project and reference it to MVC application, but lets forget about this now.

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

Accepted Answer

For a small project, it should be part of the Model. For a larger product, the repository and the associated model could be in a separate assembly.

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

Popular Answer

Well this is debatable, but i'd vote +1 for the Models folder.

The only other candidate would be App_Data, but this is generally for file-based databases (SQL Server CE .MDF, for example) and files you don't want served by IIS.

As the EDMX is an abstraction of the database, it should go into the Models folder.

If the project gets bigger, you should definetely move your EF Model into another project. To future-proof yourself from this, make your Controllers access the EDMX via Repository/Interfaces, so when you move the DAL over to another project, all you'll have to do is add the reference and add in the using statements.



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