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. Â