Show / Hide Table of Contents

    Class SqlServerIdGeneratorFactory

    Creates an instances of SqlServerIdGenerator for specified database.

    Inheritance
    System.Object
    SqlServerIdGeneratorFactory
    Implements
    IIdGeneratorFactory
    Namespace: Kros.Data.SqlServer
    Assembly: Kros.Utils.dll
    Syntax
    public class SqlServerIdGeneratorFactory : IIdGeneratorFactory
    Examples
            public class PeopleService
        {
            private IIdGeneratorFactory _idGeneratorFactory;
    
            public PeopleService(IIdGeneratorFactory idGeneratorFactory)
            {
                _idGeneratorFactory = Check.NotNull(idGeneratorFactory, nameof(idGeneratorFactory));
            }
    
            public void GenerateData()
            {
                using (var idGenerator = _idGeneratorFactory.GetGenerator("people", 1000))
                {
                    for (int i = 0; i < 1800; i++)
                    {
                        var person = new Person()
                        {
                            Id = idGenerator.GetNext()
                        };
                    }
                }
            }
        }

    Constructors

    SqlServerIdGeneratorFactory(SqlConnection)

    Initializes a new instance of the SqlServerIdGeneratorFactory class.

    Declaration
    public SqlServerIdGeneratorFactory(SqlConnection connection)
    Parameters
    Type Name Description
    System.Data.SqlClient.SqlConnection connection

    Database connection. ID generators create IDs for tables in this database.

    SqlServerIdGeneratorFactory(String)

    Initializes a new instance of the SqlServerIdGeneratorFactory class.

    Declaration
    public SqlServerIdGeneratorFactory(string connectionString)
    Parameters
    Type Name Description
    System.String connectionString

    Database connection string. ID generators create IDs for tables in this database.

    Methods

    GetGenerator(String)

    Creates an instance of IIdGenerator for table tableName.

    Declaration
    public IIdGenerator GetGenerator(string tableName)
    Parameters
    Type Name Description
    System.String tableName

    Table for which IDs will be generated.

    Returns
    Type Description
    IIdGenerator

    The instance of IIdGenerator.

    GetGenerator(String, Int32)

    Creates an instance of IIdGenerator for table tableName with specified batchSize.

    Declaration
    public IIdGenerator GetGenerator(string tableName, int batchSize)
    Parameters
    Type Name Description
    System.String tableName

    Table for which IDs will be generated.

    System.Int32 batchSize

    IDs batch size. This number of IDs will be reserved for later use.

    Returns
    Type Description
    IIdGenerator

    The instance of IIdGenerator.

    Register()

    Registers factory methods for creating an instance of factory into IdGeneratorFactories.

    Declaration
    public static void Register()

    Implements

    IIdGeneratorFactory

    See Also

    SqlServerIdGenerator
    IdGeneratorFactories
    Back to top KROS a.s.