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?
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.
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.
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.
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.
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.
It doesn't matter. I put it in the Models folder because that's where all the database stuff goes into.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With