Interface IIdGenerator
Interface for generating IDs for records in database. In general, IDs are just sequential numbers.
Namespace: Kros.Data
Assembly: Kros.Utils.dll
Syntax
public interface IIdGenerator : IDisposable
Remarks
Usually one generator generates IDs for just one table.
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()
};
}
}
}
}
Methods
GetNext()
Returns next ID.
Declaration
int GetNext()
Returns
Type | Description |
---|---|
System.Int32 | Unique ID for record in data table. |
InitDatabaseForIdGenerator()
Initializes database for using ID generator. Initialization can mean creating necessary table and stored procedure.
Declaration
void InitDatabaseForIdGenerator()