Show / Hide Table of Contents

    Class MsAccessIdGenerator

    The unique ID generator for Microsoft Access.

    Inheritance
    System.Object
    IdGeneratorBase
    MsAccessIdGenerator
    Implements
    IIdGenerator
    Inherited Members
    IdGeneratorBase.TableName
    IdGeneratorBase.BatchSize
    IdGeneratorBase.Connection
    IdGeneratorBase.GetNext()
    IdGeneratorBase.Dispose(Boolean)
    IdGeneratorBase.Dispose()
    Namespace: Kros.Data.MsAccess
    Assembly: Kros.Utils.MsAccess.dll
    Syntax
    public class MsAccessIdGenerator : IdGeneratorBase, IIdGenerator, IDisposable
    Remarks

    In general, the generator should be created using MsAccessIdGeneratorFactory.

    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

    MsAccessIdGenerator(OleDbConnection, String, Int32)

    Creates a generator for table tableName in database connection with batch size batchSize.

    Declaration
    public MsAccessIdGenerator(OleDbConnection connection, string tableName, int batchSize)
    Parameters
    Type Name Description
    System.Data.OleDb.OleDbConnection 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.

    MsAccessIdGenerator(String, String, Int32)

    Creates a generator for table tableName in database connectionString with batch size batchSize.

    Declaration
    public MsAccessIdGenerator(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 IdStore table.

    Declaration
    public static string GetIdStoreTableCreationScript()
    Returns
    Type Description
    System.String

    GetNewIdFromDbCore()

    Declaration
    protected override int GetNewIdFromDbCore()
    Returns
    Type Description
    System.Int32
    Overrides
    IdGeneratorBase.GetNewIdFromDbCore()

    InitDatabaseForIdGenerator()

    Declaration
    public override void InitDatabaseForIdGenerator()
    Overrides
    IdGeneratorBase.InitDatabaseForIdGenerator()

    Implements

    IIdGenerator

    See Also

    IdGeneratorFactories
    MsAccessIdGeneratorFactory
    Back to top KROS a.s.