SqlCodeTemplate
To base a template on the SqlCodeTemplate class, inherit from it in the template's CodeTemplate directive:
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Inherits="CodeSmith.BaseTemplates.SqlCodeTemplate" Description="Build data access layer." %>
<%@ Assembly Name="CodeSmith.BaseTemplates" %>
SqlCodeTemplate inherits from OutputFileCodeTemplate, so your template also gets the OutputFile property. On top of that, it adds helper methods for working with SQL Server databases. Most of them take a SchemaExplorer column, such as a ColumnSchema:
| Method | Description |
|---|---|
GetCSharpVariableType |
Returns the equivalent C# variable type for a database column. |
GetMemberVariableDeclarationStatement |
Returns a C# member variable declaration statement. |
GetMemberVariableDefaultValue |
Returns a default value based on a column's data type. |
GetMemberVariableName |
Returns the C# member variable name for a given identifier. |
GetPropertyName |
Returns the name of the public property for a given column. |
GetReaderMethod |
Returns the name of the typed reader method for a given column. |
GetSqlDbType |
Returns the SqlDbType for a given column. |
GetSqlParameterExtraParams |
Generates any extra parameters needed for the ADO.NET parameter statement. |
GetSqlParameterStatement |
Returns a T-SQL parameter statement for a given column. |
GetSqlParameterStatements |
Generates a statement that adds a parameter for the given column to an ADO.NET command. |
GetSqlReaderAssignmentStatement |
Returns a typed C# reader.ReadXXX() statement. |
GetValidateStatements |
Generates a batch of C# validation statements for a table's columns. |
IncludeEmptyCheck |
Determines whether a column should be checked for an empty value. |
IncludeMaxLengthCheck |
Determines whether a column's data type needs a maximum length check. |
IsUserDefinedType |
Determines whether a column uses a user-defined type. |
For the complete list, see SqlCodeTemplate Methods in the API documentation.