Question

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?

Was it helpful?

Solution

Why don't you copy the Database.tt along with PetaPoco.Core.ttinclude and PetaPoco.Generator.ttinclude itself in App_Data? That way your Database.cs will be generated there itself in App_Data and you don't have to copy paste between folders.

Further change the name of the T4 template itself change it EmployeePoco.tt and you will have it's corresponding EmployeePoco.cs. Also change the parameter RepoName in Database.tt and change it's value to EmployeePoco. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top