Using Non-Identity Integer Keys

Generally, integer keys will be identity keys, meaning that the database server will automatically assign unique (generally sequential) key values. However, integer keys could also be manually generated. This is supported by the Milos framework as well (although it is error prone and therefore not recommended).

The main difference between identity and manual integer keys is that the key type of the business object has to be set to KeyType.Integer, and also, the GetNewIntegerKey() method has to be overridden as in the following example:

public class EmployeeBO : BusinessObject { protected override void Configure() { this.MasterEntity = "Employees" ; this.PrimaryKeyField = "EmployeeID" ; this.PrimaryKeyType = EPS.Data.KeyType.Integer; } public override int GetNewIntegerKey(string EntityName, DataSet DataSetWithNewRecord) { return 1; // Return a real value here, rather than 1 } }

The tricky part is that the GetNewIntegerKey() method needs to return a unique key value (which is not the case in the example above). It is up to the the developer to ensure that the routine creates a key that is unique. This could be achieved through some kind of mechanism that generates unique integers, such as a "pseudo guid" algorithm. Another popular implementation would be to connect to the database and query some kind of key table.


Last Updated: 8/7/2006