ComponentOne DataObjects for .NET
Keys Assigned by Server or Database
DataObjects for .NET (Enterprise Edition) > Features and Techniques > Adding Rows and Primary Keys > Keys Assigned by Server or Database

It is common to allocate new primary key values on the application server or in the database itself (autoincrement keys, triggers, and so on). In this case, the real primary key values as they will appear in the database are not known until the new rows are actually inserted into the database. This is the "unknown key" problem. DataObjects for .NET solves this problem by allowing you to work with temporary key values until the rows are sent to the database for update.

Before an update, you can use arbitrary temporary values for primary keys. The only requirement is that those temporary values must be unique, not intersecting with real (after update) primary key values. For example, the temporary values can be made negative to ensure their uniqueness. This is done automatically by DataObjects for .NET if you use property setting AutoIncrement = ClientAndServer.

When the rows are created on the client, they acquire temporary primary key values (become attached), as described in Keys Assigned by Client: New Row Detached and Attached State. Rows with temporary primary key values can be used on the client without restrictions, including adding child rows related to them, and so on.

During database update, when the new rows are actually inserted into the database, DataObjects for .NET obtains final primary key values and substitutes the temporary values on the client with the final values. This client primary key value refresh can be done automatically by DataObjects for .NET if you use property setting AutoIncrement = ClientAndServer, as described in Key Assigned Automatically by Database, or it can be performed programmatically, as shown in Programmatic Key Assignment.