SqlServerCodeGenerator

Classes > DataProvider.SqlServer > SqlServerCodeGenerator

SQL Server specific code generator static methods

public static class SqlServerCodeGenerator

Methods

GenerateCode(string, string, SelectStatement, bool, GroupingConfig?)

public static Result<string, SqlError> GenerateCode(string fileName, string sql, SelectStatement statement, bool _ = false, GroupingConfig? __ = null)

Generate C# source code for a SQL file (fallback method)

Parameters:

Name Type Description
fileName String The name of the SQL file.
sql String The SQL content.
statement SelectStatement The parsed SQL statement metadata.
_ Boolean Whether a custom implementation exists (unused).
__ GroupingConfig Optional grouping configuration for parent-child relationships (unused).

Returns: SqlError> - Result with generated C# source code or error

GenerateCodeWithMetadata(string, string, SelectStatement, string, IReadOnlyList<DatabaseColumn>, bool, GroupingConfig?)

public static Result<string, SqlError> GenerateCodeWithMetadata(string fileName, string sql, SelectStatement statement, string connectionString, IReadOnlyList<DatabaseColumn> columnMetadata, bool _ = false, GroupingConfig? groupingConfig = null)

Generate C# source code for a SQL file with real database metadata

Parameters:

Name Type Description
fileName String The name of the SQL file.
sql String The SQL content.
statement SelectStatement The parsed SQL statement metadata.
connectionString String Database connection string.
columnMetadata DatabaseColumn> Real column metadata from database.
_ Boolean Whether a custom implementation exists (unused).
groupingConfig GroupingConfig Optional grouping configuration for parent-child relationships.

Returns: SqlError> - Result with generated C# source code or error

GenerateTableOperations(DatabaseTable, TableConfig)

public static Result<string, SqlError> GenerateTableOperations(DatabaseTable table, TableConfig config)

Generate C# source code for Insert/Update operations based on table configuration

Parameters:

Name Type Description
table DatabaseTable The database table metadata
config TableConfig The table configuration

Returns: SqlError> - Result with generated C# source code or error

GetColumnMetadataFromSqlAsync(string, string, IEnumerable<ParameterInfo>)

public static Task<Result<IReadOnlyList<DatabaseColumn>, SqlError>> GetColumnMetadataFromSqlAsync(string connectionString, string sql, IEnumerable<ParameterInfo> parameters)

Gets column metadata by executing the SQL query against the database. This is the proper way to get column types - by executing the query and checking metadata.

Parameters:

Name Type Description
connectionString String Database connection string
sql String SQL query to execute
parameters ParameterInfo> Query parameters

Returns: SqlError>> - Result with list of database columns with their metadata or error