I like to to keep my code first – or T4 generated – POCOs in a project separated from the DbContext. This helps me ensure my entity classes aren’t coupled to any one data access service.
When I create a new DB first EDMX model, the wizard generates a T4 template to generate all the POCOs in the same project as the DbContext. How can I modify this template to add classes to a separate project?
On closer inspection, it would probably be much easier to move the DbContext to a new project, but the T4 for this has no call to fileManager.StartNewFile so i don’t know where to begin telling it to create a file elsewhere.
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.