Using String Keys

Milos also supports the use of string keys in addition to Guids and Integers. The situation with string keys is similar to the situation with manual integer keys (see above) in that the developer has to make sure that whatever key gets generated is unique. However, string keys are somewhat easier to handle than manual integers, because strings could be converted guids. This is the default string-key implementation milos provides. String keys can be used in the following fashion:

public class CustomerBO : BusinessObject { protected override void Configure() { this.MasterEntity = "Customers" ; this.PrimaryKeyField = "CustID" ; this.PrimaryKeyType = EPS.Data.KeyType.String; } }

This example assumes that the CustID field is a string field that is big enough to hold the string representation of a Guid. This may not always be the case though. Often, a string key may be an abritrary alphanumeric key generated by some type of algorithm, as in the following example:

public class CustomerBO : BusinessObject { protected override void Configure() { this.MasterEntity = "Customers" ; this.PrimaryKeyField = "CustID" ; this.PrimaryKeyType = EPS.Data.KeyType.String; } public override int GetNewStringKey(string EntityName, DataSet DataSetWithNewRecord) { return "NEWKEY" ; // Return a real value here, rather than "NEWKEY" } }

As in the integer example Using Non-Identity Integer Keys, this version would not work in a real-live application, since the value needs to be unique. Once again, a more sophisticated algorithm would be required.


Last Updated: 8/7/2006