T4 Template

ericdc1 edited this page Jan 28, 2013 · 3 revisions

You can autogenerate your POCOs directly from your database using this T4 Template

You can also install it using Nuget

You specify a connection string (from web.config or app.config) and set a namespace and the template will generate a class per table with necessary attributes. Primary Key fields are marked with the [Key] attribute. The classes for the table names are converted to singular form (Users becomes User) and the [Table("Name")] attribute is applied.

The class and each property is virtual so you can override them in your own classes to add things like data annotations.

Check out the sample website project for example usage.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.