Where to put Entity Framework Data Model in MVC application?

后端 未结 4 1118
囚心锁ツ
囚心锁ツ 2021-02-02 15:25

Lets consider default ASP.NET MVC application folder structure, so it\'s looks like this:

-App_data
-Content
-Controllers
    HomeController.cs
-Models
    Accou         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 16:11

    Well this is debatable, but i'd vote +1 for the Models folder.

    The only other candidate would be App_Data, but this is generally for file-based databases (SQL Server CE .MDF, for example) and files you don't want served by IIS.

    As the EDMX is an abstraction of the database, it should go into the Models folder.

    If the project gets bigger, you should definetely move your EF Model into another project. To future-proof yourself from this, make your Controllers access the EDMX via Repository/Interfaces, so when you move the DAL over to another project, all you'll have to do is add the reference and add in the using statements.

提交回复
热议问题