A column with a foreign key constraint in the database can be mapped to a simple type field like an integer but it can additionally be mapped to a reference type field like Person.Address. The data in the database is always an integer. Telerik OpenAccess ORM automatically translates the integer to a reference and vice versa. It is possible to map a single column from the database to two fields in the object model - one of simple type and one of reference type.
In case of forward mapping the same column name should be set for both columns. Otherwise OpenAccess generates two columns with the default names for the respective fields.
In case of reverse mapping, by default both fields are generated. If only the reference field should be generated, this can be specified in the Options dialog of the Reverse mapping wizard. The dialog can be opened by pressing the Options button inside the Reverse mapping wizard.
This setting can be specified per column as well. In the Reverse mapping dialog select the integer column and set Generate Field to false. The integer field will not be generated in this case.
If the integer column should be there but not the reference, select the reference and press the remove button.
The shared columns are needed in cases of web pages or WCF services where it is necessary to serialize the object graph. This serialization can be a complex tree serialization or a flat one. In case of flat serialization the references must be translated to simple types like integer. If the integer column is already available, the reference can be stripped out of the serialization and only the integer field can be used. Another possible case is if only the integer value is available, like if it is coming from the web page, to set the reference the object must be loaded from the database first. If the integer field is available the value can be set directly.
The shared column can also produce problems. The base of all problems is the fact that one value in the database is mapped to two fields in memory. This means that the in memory representation of database data can have two different values. Telerik OpenAccess ORM tries to keep both fields in sync but sometimes it is not possible or not desired.
Consider the case when the reference is set to a new object that does not have a key so far because the key is set by an AUTOINC column in the database. As long as the transaction is not committed or flushed the integer value is not available.
If the integer value is changed this should not fire an update on the reference because this might be a database call. The problem is that the reference can be invalid because such data might not be in the database.
The time-frames where the fields are not in sync is bound to the transaction and usually short. If a new transaction is started OpenAccess makes sure that the fields contain the same values.