Creating the Template in CodeSmith Studio

This time, we'll use CodeSmith Studio to create the template. This will let you try out the tools in CodeSmith Studio to see how they can speed up template development. To get started, launch CodeSmith Studio and select File > New > VB Template. This will create a new template with some boiler plate code in it to remind you how the various parts of a CodeSmith template fit together. Start by modifying the CodeTemplate directive:

<%@ CodeTemplate Language="VB" TargetLanguage="T-SQL" Description="Create an HTTP Endpoint." %>

The TargetLanguage attribute is used by CodeSmith to group the template with other T-SQL templates when you use target language view in CodeSmith Explorer. This attribute is also used to determine how to syntax highlight the static content of a template. The Description attribute is used to provide a tooltip for the template.

Next, replace the rest of the sample template code with the T-SQL that we want to generate. Now we've got the starting point: a template that turns out completely static SQL.

<%@ CodeTemplate Language="VB" TargetLanguage="T-SQL" Description="Create an HTTP Endpoint." %>
CREATE PROC dbo.PersonAddressTypeProc
AS
    SELECT 
        AddressTypeID, 
        Name, 
        rowguid, 
        ModifiedDate
    FROM
    Person.AddressType
GO
CREATE ENDPOINT GetAddressType
    STATE = STARTED
AS HTTP
(
    PATH = '/AddressType',
    AUTHENTICATION = (INTEGRATED),
    PORTS = (CLEAR),
    SITE = 'localhost'
)
FOR SOAP
(
    WEBMETHOD 'AddressTypeList'
        (NAME='AdventureWorks.dbo.PersonAddressTypeProc'),
    BATCHES = DISABLED,
    WSDL = DEFAULT,
    DATABASE = 'AdventureWorks',
    NAMESPACE = 'http://AdventureWorks/AddressType'
)
GO

Of course, you don't want a static template. The next step is to start making the content dynamic.

Next: Setting up Enumerated Properties

More Information:

CodeSmith Studio

The CodeTemplate Directive