I'm using new Entity Framework 4.1 Model first approach that makes use of T4 templates to generate classes from visual model.
Can I configure that T4 templates to create POCO classes and Context classes (or at generally whatever they generate) in another project?
Please note that I don't want to move T4 template (file with .tt) to another project and then just change the template to EDMX file in persistence project. I want it to really generate that classes in another project then the location of template. Is that possible ?
Thank you for answers
Notes: this is no duplicate of question Generate POCO classes in different project to the project with Entity Framework model as author there wanted just what I don't: move 开发者_JAVA技巧the whole template together with classes generated.
I fully understand that moving the whole template will not mean that the other project will become persistence aware. Still, I have my reasons why I don't want it in the same project with POCO classes.
Multiple projects sharing the same templates
Whenever I use shared T4 templates I:
- create a solution folder
- put my generation T4 template in it and set its extension to ttinclude
- add additional T4 templates to my projects wherever needed but with tt extension
- depending on template functionality, they may only have to reference the shared ttinclude template as in this example of mine that I use to generate enum types of database lookup tables;
If you're using provided templates you will have to modify them a bit to make this work, because they will have to reference EDMX file on a different location than default. You can as well provide this path as a local variable that you override in your per-project template so it will use the overridden path instead of default defined in the ttinclude file.
精彩评论