EF 4.1 DbContext Generattor - Put Entities in different project?

前端 未结 1 729
囚心锁ツ
囚心锁ツ 2021-02-04 17:18

As a part of our application architecture, we like to define clear lines between our functional layers. A typical application solution, therefore, will contain:

  • E
1条回答
  •  醉话见心
    2021-02-04 17:42

    Sure. DbContext Generator are just two T4 templates. You can move the template generating entities to other project. You just need to modify template to point to correct EDMX file. This is default:

    string inputFile = @"Model.edmx";
    

    You must change it to relative address to your EDMX file. It will be something like:

    string inputFile = @"../Model/Model.edmx"
    

    The template will automatically use default namespace of current project for generated entities but you will have to modify the second template for context to use the new namespace so that entity types are correctly resolved from referenced assembly.

    There is small disadvantage of using template in another project - it will not update automatically when you modify model. You must always trigger entity recreation manually by using Run custom tool from context menu on template file.

    0 讨论(0)
提交回复
热议问题