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

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?

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

Accepted Answer

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.

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

Popular Answer

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



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