The idea behind the artificial fields and types feature of Telerik OpenAccess ORM is to enable developers to create and/or extend their persistent model during runtime. OpenAccess gives the opportunity to add fields of the existing compiled persistent classes or adding new persistent classes without the requirement of writing additional code and more development iterations. The artificial fields and types are described inside an xml node and that can be done dynamically depending on the application’s business logic.
Under the hood, OpenAccess takes care of transforming these entries into meaningful Type or Property Descriptors. Using the Generic Metadata Access API, OpenAccess gives the opportunity to operate on such fields and do all CRUD operations that are doable using the compiled Persistent Classes and the standard API from OpenAccess.
The above relates to the in-memory representation of the entities inside Telerik OpenAccess ORM. The relational representation of those fields is the same as with the usual persistent-capable classes. It is doable by invoking a clever mechanism that uses the runtime schema changes API and the forward mapping capabilities of Telerik OpenAccess ORM.The following code demonstrates an example of how this API can be used to update the database schema during runtime:
string ddlscript = database.GetSchemaHandler().CreateUpdateDDLScript(null); if (!string.IsNullOrEmpty(ddlscript)) database.GetSchemaHandler().ExecuteDDLScript(ddlscript);
In order to enable OpenAccess to look for artificial fields in the project, the artificial-types extension node should be added under the current mapping node:
<mapping id=" mssqlMapping">
<extension key="artificial-types" value="" />
In the following section, two main topics that form this feature will be discussed: