Entities are stored in an object storage of type IObjectStorage generally accessible from the ObjectContext.LocalStorage property. The local storage gives means to create as well as to retrieve existing entities.
Entity instances have OIDs (object identifiers). The OIDs are unique inside inheritance trees: no two instances of a particular class – be they direct instances or indirect instances, that is instances of a descendant class – can have the same OID. On the other hand, two instances of totally unrelated classes can have the same OID. In this way, we can easily accommodate with legacy databases in which primary keys are not unique across tables.
OIDs are useful in scenarios where you want to remember particular entities for later use: you query an entity’s OID, store it in a web session, in a hidden HTML field, in a text file or in whatever storage you like, and later on – possibly during a different working session – you retrieve the entity corresponding to the OID.
To accommodate with such scenarios, OIDs are of type string: this type makes it very easy to manipulate and store them. When mapped to a relational source, OIDs become primary keys. Of course primary keys are not restricted to the string type, but can be of any suitable database type. Even composite keys are supported.
To query an entity’s OID, one just makes use of the ToString() method, so that no particular API is required at the entity level. Conversely, to retrieve the entity associated with a particular OID, two methods are offered by the framework:
Note that both of these methods take the “base type” of the entity – that is its actual type or the type of one of its ancestors – as an extra argument : this is the trade-off the framework assents in order to accommodate with both polymorphism and legacy databases.
|IEntity||IEntity is an interface supported by the implementation classes of entity classes.|
|IEntityFactory||An interface supported by mappers capable to manage the lifecyle of an entity.|
|IEntityState||Interface giving access to the state of an entity.|
|IObjectStorage||An interface supported by objects capable of creating and storing entities, in addition to the capabilities provided by interface IObjectSource.|
|IOidFactory||An interface supported by OID mappers for the management of the lifecycle of OIDs.|
|IPropertyReader||An interface supported by property mappers for the reading of property values.|
|IPropertyWriter||An interface supported by property mappers for the writing of property values.|
|IReferenceReader||An interface supported by reference mappers for the reading of reference values.|
|IReferenceWriter||An interface supported by reference mappers for the writing of reference values.|
|ISingleReferenceReader||An interface supported by single reference mappers for the reading of reference values.|
|ISingleReferenceWriter||An interface supported by single reference mappers for the writing of reference values.|
|CloneMode||The specification of what to clone with the method Clone.|
|EntityStatus||The modification status of an entity.|