Search code examples
asp.net-mvcentity-frameworkdesign-patternsdirectory-structure

Where to put Entity Framework Data Model in MVC application? Specific example


First I want to refer to this post:

Where to put Entity Framework Data Model in MVC application?

My edmx will have 7-10 tables in it. Not more.

The problem is I have to build my model which I´m working with out of [lets say] 4 tables. So I´m asking myself: Are these tables real model representations and would it be correct to put the edmx file in the "Models" folder and how should I name this CONTAINER of models?

Or are 10 tables enough to create a new project? How to call the project? .DataAccess? How to name the edmx file in it?

I don´t have that much experience with MVC and EF and am trying to figure out a best practice there.

Update: This post tells me not to put it in the Models folder: "The model should be decoupled from the backend data store technology as much as possible."


Solution

  • Personally my MVC projects (regardless of size) consist of the following as a minimum:

    • Data
    • Logic
    • Site

    This structure seems to work pretty well as it separates business logic from storage and display.

    You definitally don't want to put the EDMX in the models folder as that is reserved for view models. Best practice says that view models should be entirely disconnected from your storage entities.

    In terms of naming the EDMX i normally name it after the short name of the project, the more important thing is to get the namespace right for the EDMX so your models sit in the correct namespace location.