I have an oldish ASP.NET project that I'm updating from MVC3/EF43 to MVC5/EF6.
The MVC part was a great success.
However, the EF part is not so great, and I'm looking for code placement strategies for custom partial classes so that the generated code does not overwrite my custom code.
Under EF43, the project uses Database first and T4 templates, and the ObjectContext. For my given Models/Model1.edmx
and the associated Models/Model1.tt
all the code was previous generated into Models/Model1.cs
.
In my migration to EF6, and continuing to use Database first and T4 templates, I've decided to move to the DbContext. A side effect is that I now have a Models/Model1.Context.tt
and a 'Models/Model1.Context.csand individual files have been written into
Models` for each model in the .edmx, overwriting previously declared partial classes with the generated POCOs.
I need to adopt a strategy where the generated POCOs do not overwrite my partials, and am looking for solutions.
The strategy that I have adopted is to rename my partials to Models/<Model>.Partial.cs
, but keep the original file (relatively) unchanged.
This has allowed the generated POCOs and my partials to exist in the same directory.
Because the generated POCOs had overwritten my partials, I shutdown VS, restored any overwritten models via Git, and renamed them. Then I was able to restart VS, and save the .edmx to regenerate the POCOs. I also had to include the renamed files, because they were renamed out side of VS. VS will prevent the renaming of the POCO files, if they are included under the .edmx file.