EF 4.1 DbContext Generattor - Put Entities in different project?

可紊 提交于 2019-12-03 00:26:57

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!