API Reference
#API Reference
Here's a quick summary of what the object hierarchy looks like:
- MetaBuilder
- Tables
- Name
- Columns
- DataTypes
- IsIdentity
- IsNullable
- Precision
- Scale
- Length
- IsPrimaryKey
- IsForeignKey
- ParentRelationships
- ChildRelationships
- Views
- Name
- Columns
- DataTypes
- IsIdentity
- IsNullable
- Precision
- Scale
- Length
- IsPrimaryKey
- IsForeignKey
- ParentRelationships
- ChildRelationships
- Procedures
- Name
- Parameters
- Name
- DataTypes (ignore if parameter is a table-valued parameter)
- IsTableValue
- TableValue (
Tableobject if parameter is a table-valued parameter)
- Selects
- SelectColumns
- Name
- DataTypes
- IsNullable
- SelectColumns
- Tables
SqlSharpener
DataTypeHelper
Helps map a data type to similar datatypes in different environments. Created from this reference: https://msdn.microsoft.com/en-us/library/cc716729%28v=vs.110%29.aspx
Constructor
Prevents a default instance of the class from being created.
GetMap(dataType)
Gets a single data type dictionary with values for each TypeFormat
| Name | Description |
|---|---|
| dataType |
SqlSharpener.DataTypes Type of the data. |
Returns
GetMap(lookupFormat, lookupValue)
Gets a single data type dictionary with values for each TypeFormat by finding the specified entry in the list of data type dictionaries.
| Name | Description |
|---|---|
| lookupFormat |
SqlSharpener.TypeFormat The TypeFormat of the lookupValue parameter. |
| lookupValue |
System.String The value to identify the dictionary to return. |
Returns
The first data type dictionary that contains the specified TypeFormat and value.
Instance
Gets the instance.
ToDataType(sourceDataType, sourceFormat, destinationFormat)
Converts the specified source data type into the specified destination data type.
| Name | Description |
|---|---|
| sourceDataType |
System.String The source data type. For example bigint. |
| sourceFormat |
SqlSharpener.TypeFormat The format of the the sourceDataType parameter. |
| destinationFormat |
SqlSharpener.TypeFormat The format to convert the sourceDataType parameter to. |
Returns
The converted data type.
System.NotSupportedException:
MetaBuilder
Creates a model from the specified sql files.
Constructor(sqlPaths)
Initializes a new instance of the class.
| Name | Description |
|---|---|
| sqlPaths |
System.String[] The paths to the *.sql files. |
LoadModel
Creates a new TSqlModel, loads all *.sql files specified in the SqlPaths property into the new model, and then parses the model.
System.InvalidOperationException: No path to *.sql files exists in SqlPaths properties.
LoadModel(model)
Parses the specified TSqlModel
| Name | Description |
|---|---|
| model |
Microsoft.SqlServer.Dac.Model.TSqlModel The model. |
LoadModel(sqlStatements)
Creates a new TSqlModel, loads each specified sql statement into the new model, and then parses the model
| Name | Description |
|---|---|
| sqlStatements |
System.String[] One or more sql statements to load, such as CREATE TABLE or CREATE PROCEDURE statements. |
ProcedurePrefix
Gets or sets the prefix to strip off the procedure name when generating the method name.
Procedures
Objects representing the meta data parsed from stored procedures in the model.
SqlPaths
List of directories where *.sql exist that should be added to the model.
Tables
Objects representing the meta data parsed from the tables in the model.
Views
Objects representing the meta data parsed from the views in the model.
Model.Column
Represents a column in a table.
Constructor(Microsoft.SqlServer.Dac.Model.TSqlObject,Microsoft.SqlServer.Dac.Model.TSqlObject,System.Collections.Generic.IEnumerable{Microsoft.SqlServer.Dac.Model.TSqlObject},System.Collections.Generic.IDictionary{Microsoft.SqlServer.Dac.Model.TSqlObject,System.Collections.Generic.IEnumerable{Microsoft.SqlServer.TransactSql.ScriptDom.ForeignKeyConstraintDefinition}})
Initializes a new instance of the class.
| Name | Description |
|---|---|
| tSqlObject |
Unknown type The TSqlObject representing the column. |
| tSqlTable |
Unknown type The table or view this column belongs to. |
| primaryKeys |
Unknown type The primary keys. |
| foreignKeys |
Unknown type The foreign keys. |
Constructor(System.String,System.Collections.Generic.IDictionary{SqlSharpener.TypeFormat,System.String},System.Boolean,System.Boolean,System.Int32,System.Int32,System.Int32,System.Boolean,System.Boolean,System.Collections.Generic.IEnumerable{SqlSharpener.Model.RelationshipIdentifier},System.Collections.Generic.IEnumerable{SqlSharpener.Model.RelationshipIdentifier})
Initializes a new instance of the class.
| Name | Description |
|---|---|
| name |
Unknown type The name. |
| dataTypes |
Unknown type The data types. |
| isIdentity |
Unknown type if set to true [is identity]. |
| isNullable |
Unknown type if set to true [is nullable]. |
| precision |
Unknown type The precision. |
| scale |
Unknown type The scale. |
| length |
Unknown type The length. |
| isPrimaryKey |
Unknown type if set to true [is primary key]. |
| isForeignKey |
Unknown type if set to true [is foreign key]. |
| parentRelationships |
Unknown type The parent relationships. |
| childRelationships |
Unknown type The child relationships. |
ChildRelationships
Gets or sets the relationships where this column is a foreign key on other tables.
DataTypes
Gets the data types.
IsForeignKey
Gets or sets a value indicating whether this instance is foreign key.
IsIdentity
Gets or sets a value indicating whether this instance is an identity column.
IsNullable
Gets or sets a value indicating whether this instance is nullable.
IsPrimaryKey
Gets or sets a value indicating whether this instance is primary key.
Length
Gets or sets the length.
Name
Gets the name.
ParentRelationships
Gets or sets the relationships where this column is a foreign key.
Precision
Gets or sets the precision.
Scale
Gets or sets the scale.
Model.Parameter
Represents a parameter of a stored procedure.
Constructor(Microsoft.SqlServer.Dac.Model.TSqlObject,System.Collections.Generic.IEnumerable{Microsoft.SqlServer.Dac.Model.TSqlObject},System.Collections.Generic.IDictionary{Microsoft.SqlServer.Dac.Model.TSqlObject,System.Collections.Generic.IEnumerable{Microsoft.SqlServer.TransactSql.ScriptDom.ForeignKeyConstraintDefinition}})
Initializes a new instance of the class.
| Name | Description |
|---|---|
| tSqlObject |
Unknown type The TSqlObject representing the parameter. |
| primaryKeys |
Unknown type The primary keys. |
| foreignKeys |
Unknown type The foreign keys. |
Constructor(System.String,System.Collections.Generic.IDictionary{SqlSharpener.TypeFormat,System.String},System.Boolean,SqlSharpener.Model.Table)
Initializes a new instance of the class.
| Name | Description |
|---|---|
| name |
Unknown type The name. |
| dataTypes |
Unknown type The data types. |
| isOutput |
Unknown type if set to true [is output]. |
DataTypes
Gets the data types for this parameter.
IsOutput
Gets a value indicating whether this instance is an output parameter.
Name
Gets the name.
TableValue
Gets the table representing this parameter if it is a table variable parameter.
Model.Procedure
Represents a stored procedures
Constructor(Microsoft.SqlServer.Dac.Model.TSqlObject,System.String,System.Collections.Generic.IEnumerable{Microsoft.SqlServer.Dac.Model.TSqlObject},System.Collections.Generic.IDictionary{Microsoft.SqlServer.Dac.Model.TSqlObject,System.Collections.Generic.IEnumerable{Microsoft.SqlServer.TransactSql.ScriptDom.ForeignKeyConstraintDefinition}})
Initializes a new instance of the class.
| Name | Description |
|---|---|
| prefix |
Unknown type The prefix used on stored procedure names. |
Constructor(name, rawName, prefix, parameters, selects)
Initializes a new instance of the class.
| Name | Description |
|---|---|
| name |
System.String The name to use for methods. |
| rawName |
System.String The raw name of the stored procedure. |
| prefix |
System.String The prefix used on stored procedure names. |
| parameters |
System.Collections.Generic.IEnumerable{SqlSharpener.Model.Parameter} The parameters. |
| selects |
System.Collections.Generic.IEnumerable{SqlSharpener.Model.Select} The selects. |
Name
Gets the name used for methods.
Parameters
Gets the parameters.
Prefix
Gets the prefix.
RawName
Gets the raw name of the stored procedure.
Selects
Gets the selects.
Model.Select
Represents a SELECT statement in a stored procedure.
Constructor(Microsoft.SqlServer.TransactSql.ScriptDom.QuerySpecification,System.Collections.Generic.IDictionary{System.String,SqlSharpener.DataType})
Initializes a new instance of the class.
| Name | Description |
|---|---|
| querySpecification |
Unknown type The query specification. |
| bodyColumnTypes |
Unknown type The body column types. |
Constructor(System.Collections.Generic.IEnumerable{SqlSharpener.Model.SelectColumn},System.Boolean,System.Collections.Generic.IDictionary{System.String,System.String})
Initializes a new instance of the class.
| Name | Description |
|---|---|
| columns |
Unknown type The columns. |
| isSingleRow |
Unknown type if set to true the select statement uses a TOP 1 clause or is a function call. |
| tableAliases |
Unknown type The table aliases. |
Columns
Gets the columns.
FillOuterJoins(outerJoinedTables, qualifiedJoin, isParentOuterJoined)
Traverses the joins and gets a list of tables that have been outer joined.
| Name | Description |
|---|---|
| outerJoinedTables |
System.Collections.Generic.List{System.String} The outer joined tables list. |
| qualifiedJoin |
Microsoft.SqlServer.TransactSql.ScriptDom.QualifiedJoin The qualified join. |
| isParentOuterJoined |
System.Boolean if set to true a parent join was outer joined. |
IsSingleRow
Gets a value indicating whether this SELECT uses a TOP 1 clause or is a function call.
TableAliases
Gets the table aliases.
Model.SelectColumn
Represents a column in a SELECT statement in a stored procedure.
Constructor(Microsoft.SqlServer.TransactSql.ScriptDom.SelectScalarExpression,System.Collections.Generic.IDictionary{System.String,SqlSharpener.DataType},System.Collections.Generic.IDictionary{System.String,System.String},System.Collections.Generic.IEnumerable{System.String})
Initializes a new instance of the class.
| Name | Description |
|---|---|
| selectScalarExpression |
Unknown type The select scalar expression. |
| bodyColumnTypes |
Unknown type The body column types. |
| tableAliases |
Unknown type The table aliases. |
| outerJoinedTables |
System.Collections.Generic.List{System.String} The aliases or names of tables that were outer joined. Used to determine if a non-nulllable column could still be null. |
System.InvalidOperationException: Could not find column within BodyDependencies: + fullColName
Constructor(System.String,System.Collections.Generic.IDictionary{SqlSharpener.TypeFormat,System.String},System.Boolean)
Initializes a new instance of the class.
| Name | Description |
|---|---|
| name |
System.String The name or alias. |
| dataTypes |
Unknown type The data types. |
| isNullable |
Unknown type if set to true [is nullable]. |
DataTypes
Gets the data types.
GetFullColumnName(System.Collections.Generic.IDictionary{System.String,System.String},System.Collections.Generic.IList{Microsoft.SqlServer.TransactSql.ScriptDom.Identifier})
Gets the fully qualified column name with any table aliases resolved.
| Name | Description |
|---|---|
| tableAliases |
Unknown type The table aliases. |
| identifiers |
Unknown type The identifiers in the MultiPartIdentifier. |
Returns
The fully qualified column name.
IsNullable
Gets or sets a value indicating whether this instance is nullable.
Name
Gets the name or alias.
Model.Table
Represents a table in the model.
Constructor(Microsoft.SqlServer.Dac.Model.TSqlObject,System.Collections.Generic.IEnumerable{Microsoft.SqlServer.Dac.Model.TSqlObject},System.Collections.Generic.IDictionary{Microsoft.SqlServer.Dac.Model.TSqlObject,System.Collections.Generic.IEnumerable{Microsoft.SqlServer.TransactSql.ScriptDom.ForeignKeyConstraintDefinition}})
Initializes a new instance of the class.
| Name | Description |
|---|---|
| tSqlObject |
Unknown type The TSqlObject representing the table. |
| primaryKeys |
Unknown type The primary keys. |
| foreignKeys |
Unknown type The foreign keys. |
Constructor(name, columns)
Initializes a new instance of the class.
| Name | Description |
|---|---|
| name |
System.String The name of the table. |
| columns |
System.Collections.Generic.IEnumerable{SqlSharpener.Model.Column} The columns. |
Columns
Gets the columns.
Name
Gets the name of the table.
Model.View
Represents a view in the model.
Constructor(Microsoft.SqlServer.Dac.Model.TSqlObject,System.Collections.Generic.IEnumerable{Microsoft.SqlServer.Dac.Model.TSqlObject},System.Collections.Generic.IDictionary{Microsoft.SqlServer.Dac.Model.TSqlObject,System.Collections.Generic.IEnumerable{Microsoft.SqlServer.TransactSql.ScriptDom.ForeignKeyConstraintDefinition}})
Initializes a new instance of the class.
| Name | Description |
|---|---|
| tSqlObject |
Unknown type The TSqlObject representing the view. |
| primaryKeys |
Unknown type The primary keys. |
| foreignKeys |
Unknown type The foreign keys. |
Constructor(name, columns)
Initializes a new instance of the class.
| Name | Description |
|---|---|
| name |
System.String The name of the view. |
| columns |
System.Collections.Generic.IEnumerable{SqlSharpener.Model.Column} The columns. |
Columns
Gets the columns.
Name
Gets the name of the view.
ProcedureHelper
Helper class to handle some of the more complex code generation.
GetDtoObject(proc, indent)
Gets the DTO return objects that represent a row of each result set of each procedure.
| Name | Description |
|---|---|
| proc |
SqlSharpener.Model.Procedure The procedure to generate the DTO from. |
| indent |
System.Int32 The number of tabs to indent the generated code. |
Returns
The generated DTO objects.
GetExecuteStatement(proc, indent)
Gets the generated statement that executes the stored procedure and loads the results into the return variable.
| Name | Description |
|---|---|
| proc |
SqlSharpener.Model.Procedure The procedure to get the generated execute statement for. |
| indent |
System.Int32 The number of tabs to indent the generated code. |
Returns
The generated code.
GetMethodParamList(proc, genericTableValue, includeType, convertType)
Gets the parameter list for the method.
| Name | Description |
|---|---|
| proc |
SqlSharpener.Model.Procedure The procedure to get the parameter list for. |
| genericTableValue |
System.Boolean if set to true [generic table value]. |
| includeType |
System.Boolean if set to true [include type]. |
| convertType |
System.Boolean if set to true [convert type]. |
Returns
The generated parameter list.
GetMethodParamListForInputDto(proc)
Gets the method parameter list for methods that call an overload with input DTO properties as parameters.
| Name | Description |
|---|---|
| proc |
SqlSharpener.Model.Procedure The proc. |
Returns
GetMethodParamListForObjectArray(proc)
Gets the method parameter list for object array.
| Name | Description |
|---|---|
| proc |
SqlSharpener.Model.Procedure The proc. |
Returns
GetNamespace(outputNameSpace)
Scrubs the outputNamespace parameter to ensure it is not null.
| Name | Description |
|---|---|
| outputNameSpace |
System.String The outputNameSpace T4 parameter. |
Returns
The value of outputNameSpace if not null.
System.ArgumentNullException: outputNamespace cannot be null.
GetReturnType(proc)
Gets the type of object the procedure's function will return.
| Name | Description |
|---|---|
| proc |
SqlSharpener.Model.Procedure The procedure to get the return type for. |
Returns
The generated return type.
GetReturnVariable(proc)
Gets the variable declaration statement for the return value.
| Name | Description |
|---|---|
| proc |
SqlSharpener.Model.Procedure The procedure to get the return variable declaration statement. |
Returns
The generated declaration statement.
GetReturnXmlComment(proc)
Gets the Xml comment to place in the <returns%gt; element.
| Name | Description |
|---|---|
| proc |
SqlSharpener.Model.Procedure The procedure to get the return variable declaration statement. |
Returns
The Xml comment
GetSqlParamList(proc, indent)
Gets the generated SqlParameter objects with assigned values.
| Name | Description |
|---|---|
| proc |
SqlSharpener.Model.Procedure The procedure to get the generated SqlParameters for. |
| indent |
System.Int32 The number of tabs to indent the generated code. |
Returns
The generated SqlParameters
StoredProceduresTemplate
Class to produce the template output
Initialize
Initialize the template
outputNamespace
Access the outputNamespace parameter of the template.
procedurePrefix
Access the procedurePrefix parameter of the template.
sqlPaths
Access the sqlPaths parameter of the template.
TransformText
Create the template output
TypeFormat
The different types of datatypes available.
DbTypeEnum
The database type enum
DotNetFrameworkType
The dot net framework type
SqlDataReaderDbType
The SQL data reader database type
SqlDataReaderSqlType
The SQL data reader SQL type
SqlDbTypeEnum
The SqlDbTypeEnum type
SqlServerDbType
The SQL server database type