Where should I put my Entity-Framework DataContext class in ASP.NET MVC's "best practice" folder?

asp.net-mvc directory-structure entity-framework

Question

Entity Framework DataContext classes have been found in a few projects' "Models" folders, however because this isn't truly a model, it doesn't seem appropriate.

The IDatabaseInitializer class and my DataContext are currently located at the root of my project, which annoys me as well.

Do I simply leave them at the root or a folder titled "Data" or something like, or is there a standard or recommended procedure for this?

1
12
5/18/2011 9:27:52 AM

Accepted Answer

Since the model is what preserves the state of your application, one might argue that it is the model. People placed it there for that reason.

It should go there if you're a good boy and employ an abstraction/repository layer.

Put it in the models folder if your Controllers are speaking to the EF context directly (a terrible idea). There is no reason to physically conceal anything that is not conceptually abstracted.

9
10/10/2018 8:29:39 AM

Popular Answer

It is irrelevant. Due to the fact that all database-related files are stored in the Models folder, I placed it there.



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