How do I adapt the Entity Framework POCO T4 template to create classes in a separate project?

旧时模样 提交于 2019-12-04 15:51:32

You can exclude the .tt file from your DAL project and then add it as a link in another project.

This means you won't have to alter the template as it can see your model.

The files produced when you run the template will be included in your data objects assembly, although the physical files will be in your DAL project.

The only downside is that you will have to manually run the custom tool when you update your model.

Id say:

1.- Create a file in your model project (MyProject.Model proyect), a .tt file with your desired name... (MyModel.tt for this example)

2.- Go to DAL proyect, open the WhateverModel.tt file and copy the content to MyModel.tt...

3.- Delete WhateverModel.tt form DAL proyect.

4.- Look in MyModel.tt for:

const string inputFile = @"WhateverModel.edmx";

5.- And replace it with:

const string inputFile = @"..\TheRelativeRouteToYourEdmxFileGoesHere.edmx";

6.- And... Run custom tool to generate your model.

Note: 7.- For sure you will have to change few using directives and namespaces but it works for me.

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