Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In ASP.NET MVC, where is the "best practice" place (folder) to put my Entity-Framework DataContext class?

I've seen a few projects with Entity Framework DataContext classes in the "Models" folder, but since it's not really a model, this doesn't feel right.

Currently my DataContext (along with the IDatabaseInitializer class) live in the root of my project, but that bugs me too.

Is there a common/best practice for this, or should I just leave them in the root or a folder called Data or something?

like image 340
Danny Tuppeny Avatar asked May 18 '11 09:05

Danny Tuppeny


People also ask

How can add Entity Framework in ASP NET MVC?

Right-click the Controllers folder in Solution Explorer, select Add, and then click New Scaffolded Item. In the Add Scaffold dialog box, select MVC 5 Controller with views, using Entity Framework, and then choose Add.

Which MVC folder of ASP Net is used for storing application data?

By default, MVC projects include the following folders: App_Data, which is the physical store for data. This folder has the same role as it does in ASP.NET Web sites that use Web Forms pages. Content, which is the recommended location to add content files such as cascading style sheet files, images, and so on.

What is App_Start folder in ASP NET MVC?

The App_Start folder of MVC application is used to contain the class files which are needed to be executed at the time the application starts. The classes like BundleConfig, FilterConfig, IdentityConfig, RouteConfig, and Startup. Auth etc. are stored within this folder.

Which folder in an MVC application contains the style definition files?

Content Folder This folder contains all the static files, such as css, images, icons, etc. The Site. css file inside this folder is the default styling that the application applies.


2 Answers

Arguably it is the model, since it what maintains the state of your application. That's why people put it there.

If you're a good boy and use an abstraction/repository layer - it should go there.

If your Controllers are talking directly to the EF context (bad idea), then put it in the models folder - no need to physically hide something you're not logically abstracting.

like image 64
RPM1984 Avatar answered Oct 03 '22 14:10

RPM1984


It doesn't matter. I put it in the Models folder because that's where all the database stuff goes into.

like image 24
ZippyV Avatar answered Oct 03 '22 14:10

ZippyV