SqlCodeTemplate
To base a template on the SqlCodeTemplate class, you inherit from this class in your template's CodeTemplate directive:
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Inherits="SqlCodeTemplate" Description="Build data access layer." %> <%@ Assembly Name="CodeSmith.BaseTemplates" %>
The SqlCodeTemplate class contains numerous utility methods designed to make it easier to work with SQL databases. These include:
- 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 based on a given column. Â
- GetSqlParameterExtraParams - Generates any extra parameters that are needed for the ADO parameter statement. Â
- GetSqlParameterStatement - Returns a T-SQL parameter statement based on the given column. Â
- GetSqlParameterStatements - Generates an assignment statement that adds a parameter to a ADO object for the given column. Â
- GetSqlReaderAssignmentStatement - Returns a typed C# reader.ReadXXX() statement. Â
- GetValidateStatements - Generates a batch of C# validation statements based on the column. Â
- IncludeEmptyCheck - Determines if a given column should use a check for an Empty value. Â
- IncludeMaxLengthCheck - Determines if the given column's data type requires a maximum length to be defined. Â
- IsUserDefinedType - Determine if the given column is using a UDT. Â
For a complete listing of all SqlCodeTempalate methods please refer to the API documentation.