If you are using Micro-ORM which doesn’t have fancy UI that generate your data model for you, or you want a free tool to generate POCO classes for you, I’ve got a solution for you. Personally I prefer using T4 template that PetaPoco provides, so let’s see how you can use it.
First, install/add PetaPoco to your project using Nuget:
1. Open **Package Manager Console** and type `install-package petapoco` 2. Wait until package downloaded and installed to your project.
Second, modify T4 template to generate POCO classes for you:
Database.ttfile and modify Settings part.
ConnectionStringNamewrite your database connection string name which located in app.config or web.config.
Namespacewrite the namespace for generated Poco classes.
RepoNamewrite Repository name, this is optional and recommended if you’ll use PetaPoco.
ClassPerfexwrite required class name prefix, this is optional.
ClassSuffixwrite required class name suffix, this is optional.
- Save the file.
Third, congratulation your POCO classes and Repo generated under Database.tt –> Database.cs.
- Make sure you set
ConnectStringor T4 template will not work.
- If you faced C# issue during …