Show / Hide Table of Contents

    Class SqlServerIdGenerator

    The unique ID generator for Microsoft SQL Server.

    Inheritance
    System.Object
    IdGeneratorBase
    SqlServerIdGenerator
    Implements
    IIdGenerator
    Inherited Members
    IdGeneratorBase.TableName
    IdGeneratorBase.BatchSize
    IdGeneratorBase.Connection
    IdGeneratorBase.GetNext()
    IdGeneratorBase.Dispose(Boolean)
    IdGeneratorBase.Dispose()
    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 connection or tableName is null.

    System.ArgumentException

    Value of batchSize is less or equal than 0.

    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 connectionString or tableName is null.

    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
    IdGeneratorBase.CreateConnection(String)

    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
    IdGeneratorBase.GetNewIdFromDbCore()

    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()
    Overrides
    IdGeneratorBase.InitDatabaseForIdGenerator()

    Implements

    IIdGenerator

    See Also

    IdGeneratorFactories
    SqlServerIdGeneratorFactory
    Back to top KROS a.s.