Class MsAccessIdGenerator
The unique ID generator for Microsoft Access.
Implements
Inherited Members
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 |
System.ArgumentException | Value of |
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 |
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 IdStore
table.
Declaration
public static string GetIdStoreTableCreationScript()
Returns
Type | Description |
---|---|
System.String |
GetNewIdFromDbCore()
Declaration
protected override int GetNewIdFromDbCore()
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
InitDatabaseForIdGenerator()
Declaration
public override void InitDatabaseForIdGenerator()