| Milos How-To |
| Using Non-Identity Integer Keys |
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.