Print
Add To Favorites
Email To Friend
Rate This Article
|
Automatically Generate Code Using Visual Studio's Text Template Transformation Toolkit (T4)
|
Published:
24 May 2011
|
Abstract
Visual Studio has built in support for generating code called the Text Template Transformation Toolkit. This article will demostrate how to create a class with a property for each column in a database table. The sample can easily be extended to fit any pattern you use when developing applications. |
|
by Vince Varallo
Feedback
|
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days):
28181/
74
|
|
|
Introduction |
How many times have you found yourself creating a class that
has a property for each field in a table, or creating select, insert, update,
and delete stored procedures for each table in a database? As a developer even
we are subject to such mundane tasks which, as a developer, we are supposed to
automate. Did you know that Visual Studio has a built in toolkit which will
allow you to automatically generate code for these tasks and it is free? If
you've installed Visual Studio then you already have it. It's called the Text
Template Transformation Toolkit (T4) and it works right within Visual Studio.
This article will demonstrate how to create a C# class file
that is generated by T4. The class will contain a property for each field in
the database. The example is simple but it will demonstrate the power of the
toolkit and you can enhance the code to match the patterns you follow. The
code for the sample can be found here.
The example code uses the AdventureWorks sample database
which you can download here. Once
you've installed the database you need to create a SQL Login that the application
can use to connect to the database. My sample code expects a SQL Login to
be called "aspalliance" and the password should be set to
"aspalliance".
|
|
|
User Comments
Title:
nfl jerseys cheap
Name:
NIKE NFL jerseys
Date:
2012-07-02 10:12:01 AM
Comment:
http://www.jersey2shop.com http://www.cheapjersey2store.com http://www.jerseycaptain.com http://www.yourjerseyhome.com We are professional jerseys manufacturer from china,wholesal.cheap nike nfl jerseys, mlb jerseys, nhl jerseys,nba jerseys and shoes Cheap NFL,NBA,MLB,NHL ,heap jerseys,2012 nike nfl Jerseys,nba jersey and shorts,oklahoma city thunder jersey,official jeremy lin new york knicks jersey,NFL Jerseys Wholesale,blake griffin jersey blue,NFL jerseys For Sale online.All Our Jerseys Are Sewn On and Directly From Chinese Jerseys Factory ,Wholesale cheap jerseys,Cheap mlb jerseys,]Nike NFL Jerseys,Cheap China Wholesae,Wholesale jerseys From China,2012 nike nfl Jerseys,Jerseys From China,,2012 nike nfl Jerseys,Revolution 30 nba jerseys,jersey of nba chicago bulls direk rose ,nfl jerseys,green bay packers jerseys wholesale,Buffalo Bills nike nfl jerseys sale,good supplier soccer jerseys,cool base mlb jerseys,Revolution 30 nba jerseys,2012 stanley cup nhl jersey, We are professional jerseys manufacturer from china,wholesal.cheap nike nfl jerseys, mlb jerseys, nhl jerseys,nba jerseys and shoes. www.yourjerseyhome.com
|
Title:
External
Name:
Manikandan Ganesan
Date:
2011-06-19 6:26:51 PM
Comment:
Hi,
I used to create Project and Item templates before start any project and that helps me a lot. This is useful information and thanks for posting.
Thanks, Mani
|
Title:
External
Name:
Pyrros
Date:
2011-06-10 12:54:06 PM
Comment:
How can we use this template to generate code outside this project (from another project)? Something like Add>New Item… and select the template above?
|
Title:
mr
Name:
henry
Date:
2011-05-25 6:28:02 AM
Comment:
Nice one. Pls can u modify it to iclude a method to insert to the able
|
Title:
Mr.
Name:
Ranjan
Date:
2011-05-25 4:37:19 AM
Comment:
A very good and useful thing i have found in this article for my project. Many times we work on the project which is n-tier architecture and coding for business layer is little time taking to create classes for each and every table of database in our project. So it makes it easy for developer to save their time.
|
Title:
Mr.
Name:
S Krupa Shankar
Date:
2011-05-24 10:40:54 PM
Comment:
A very good, short and crisp introduction.
And should it be dt.Columns instead of dt.Rows?
|
|
Product Spotlight
|
|