Class SqlServerIdGenerator
The unique ID generator for Microsoft SQL Server.
Implements
Inherited Members
Namespace: Kros.Data.SqlServer
Assembly: Kros.Utils.dll
Syntax
public class SqlServerIdGenerator : IdGeneratorBase, IIdGenerator, IDisposable
Remarks
In general, the generator should be created using SqlServerIdGeneratorFactory.
Examples
Constructors
SqlServerIdGenerator(SqlConnection, String, Int32)
Creates a generator for table tableName in database connection
with batch size batchSize.
Declaration
public SqlServerIdGenerator(SqlConnection connection, string tableName, int batchSize)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Data.SqlClient.SqlConnection | connection | Database connection. |
| System.String | tableName | Table name, for which IDs are generated. |
| System.Int32 | batchSize | IDs batch size. Saves round trips to database for IDs. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Value of |
| System.ArgumentException | Value of |
SqlServerIdGenerator(String, String, Int32)
Creates a generator for table tableName in database connectionString
with batch size batchSize.
Declaration
public SqlServerIdGenerator(string connectionString, string tableName, int batchSize)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | connectionString | Connection string to the database. |
| System.String | tableName | Table name, for which IDs are generated. |
| System.Int32 | batchSize | IDs batch size. Saves round trips to database for IDs. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Value of |
| System.ArgumentException |
Methods
CreateConnection(String)
Declaration
protected override DbConnection CreateConnection(string connectionString)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | connectionString |
Returns
| Type | Description |
|---|---|
| System.Data.Common.DbConnection |
Overrides
GetIdStoreTableCreationScript()
Returns SQL script for creating table in database for storing IDs.
Declaration
public static string GetIdStoreTableCreationScript()
Returns
| Type | Description |
|---|---|
| System.String |
GetNewIdFromDbCore()
Declaration
protected override int GetNewIdFromDbCore()
Returns
| Type | Description |
|---|---|
| System.Int32 |
Overrides
GetStoredProcedureCreationScript()
Returns SQL script for creating stored procedure, which generates IDs.
Declaration
public static string GetStoredProcedureCreationScript()
Returns
| Type | Description |
|---|---|
| System.String |
InitDatabaseForIdGenerator()
Declaration
public override void InitDatabaseForIdGenerator()