I am using PetaPoco Micro-ORM with my ASP.NET 4.0 project.
PetaPoco T4 template (Database.tt) generated a file Database.cs. I want to change the name and location of this auto-generated file containing mappings to the database tables. I therefore, copied this file to the APP_DATA folder of my solution explorer and renamed it to EmployeePOCO.cs.
The problem is when I want to update the model (EmployeePOCO.cs) from the database. Each time I delete the old Database.cs file and re-generate it using Database.tt. Than I copy this new Database.cs file to APP_DATA and rename it to EmployeePOCO.cs.
Is there a way to update existing EmployeePOCO.cs file?
Why don’t you copy the
Database.ttalong withPetaPoco.Core.ttincludeandPetaPoco.Generator.ttincludeitself inApp_Data? That way your Database.cs will be generated there itself inApp_Dataand you don’t have to copy paste between folders.Further change the name of the T4 template itself change it
EmployeePoco.ttand you will have it’s correspondingEmployeePoco.cs. Also change the parameterRepoNamein Database.tt and change it’s value toEmployeePoco. You should be good to go after that.Arguably, a better approach is to add a new class library project to your project solution and add it’s reference to your web project. The class library should contain all this data access code (the PetaPoco.cs and other T4 templates along with other data access classes), not your App_Data folder. You can use repository pattern for PetaPoco.
Check out this blog post:
http://programmerdave.com/mvc3-petapoco-repository/
You can customize this class according to your project but it is a good starting point.