MetadataContainer
Telerik Data Access provides the MetadataContainer class as a central runtime API that you can use to interact with the Metadata Model in the context of an application. The MetadataContainer class aggregates metadata from specific item collections that are individually responsible for loading different types of metadata.
A MetadataContainer can be easily instantiated via the OpenAccessContext's Metadata property.
using (FluentModel dbContext = new FluentModel())
{
MetadataContainer metadataContainer = dbContext.Metadata;
}
Using dbContext As New FluentModel()
Dim _metadataContainer As MetadataContainer = dbContext.Metadata
End Using
Item Collections
The MetadataContainer class aggregates metadata from specific item collections. Item collections reflect the different types of models in an application that uses the Telerik Data Access ORM. The following are the Item Collections that form the metadata model contents:
- PersistentTypes – this is a collection of MetaType objects which represent all the persistent classes associated with the database object that returns the MetadataContainer. This is the top level item collection that represents the conceptual layer of the metadata model. It is a list of types that are mapped to the corresponding artifacts like tables available in the relational store.
-
Tables – list of tables that are available in the current container instance. During runtime the Tables collection contains both Tables and Views, because the Telerik Data Access runtime threats them in the same way.
This is the main entry point for the relational layer of the metadata model. - Views – list of views that are available in the current container instance. This collection is used only during design-time by Telerik Data Access. During runtime the views are handled in the same manner as the tables.
- Constraints – this is a collection of MetaConstraint items that describe the database foreign key constraints which connect the tables. If the information inside the current container instance is populated by an already mapped model, it will contain only the constraints that are involved in the actual model (not all that are available in the relational store).
- StoredProcedures - list of stored procedures that are available in the current container instance. If the information inside the current container instance is populated by an already mapped model, it will contain only the stored procedures that are auto-generated for CRUD operations related to the model (the reverse-mapped procedures are directly generated as static instances on a static class and they are not contained currently in the collection).
- Indexes – list of indexes that are available in the current container instance. If the information inside the current container instance is populated by an already mapped model, it will contain only the indexes that are involved in the actual model (not all that are available in the relational store).
- Interfaces - gets a list of persistent interfaces that can be implemented by some of the persistent types that are part of the current container instance.
- Structs - gets a list of persistent structs that can be referenced by some of the persistent types that are part of the current container instance.
- Schemas - an additional collection as part of the MetadataContainer. It is a collection of the names of all database schemas that are part of the mapped database.
- Associations - gets a list of associations that connect pairs of persistent types.
- Constraints - gets a list of constraints that are available in the current container instance.
DefaultMapping Settings
The metadata container exposes API for configuring the default mapping behavior. You can do this via the DefaultMapping property, which returns an instance of the DefaultMapping class. You can set the following properties:
-
CacheStrategy - the CacheStrategy property is related to the 2nd level cache. When the 2nd level cache is enabled, the CacheStrategy property specifies whether objects of that type should be cached or not. The following cache policies are available:
- No - do not cache instances of this class.
- Yes - cache instances of this class.
- All - cache all instances of this class as soon as an instance is requested. All rows from its table will be read and cached whenever an instance is requested but not found in cache. This may work well for small static tables.
- InheritanceStrategy - controls the default value for the inheritance strategy (flat, vertical or horizontal).
-
DiscriminatorValue - controls how the discriminator value is calculated. It could be:
- Hash - defines that the hash value of the full name of the class is used.
- Name - the name of the class is used for discriminator value.
- FullName - the full name of the class (namespace+name) is used.
- UseStoredProceduresForDelete - controls whether stored procedures are used for delete operations.
- UseStoredProceduresForInsert - controls whether stored procedures are used for insert operations.
- UseStoredProceduresForUpdate - controls whether stored procedures are used for update operations.
- UseDelimitedSQL - controls if plain or delimited SQL is used.
- NullForeignKey - controls if foreign key columns can accept null values.
- OptimisticConcurrencyControlStrategy - controls the default value for the concurrency control strategy.
- AlwaysCreateIndexOnJoinTableValueColumns - by default, Telerik Data Access creates indexes on the non-primary key columns (value columns) of join tables only if there is a Navigation Member for the value column. Switching this option to True would mean that all join tables will have indexes defined on their value columns.
If nothing is specified on class/table level, this default behavior is used. The Telerik Data Access mapping mechanism is based on this default mechanism, specific mappings should only be specified if they are different from the default mapping.
The best way to configure the default mapping behavior is to override the OnDatabaseOpen method in your context class.
public partial class FluentModel
{
protected override void OnDatabaseOpen( Telerik.OpenAccess
.BackendConfiguration backendConfiguration,
Telerik.OpenAccess.Metadata.MetadataContainer metadataContainer )
{
metadataContainer.DefaultMapping.InheritanceStrategy =
Telerik.OpenAccess.InheritanceStrategy.Horizontal;
base.OnDatabaseOpen( backendConfiguration, metadataContainer );
}
}
Partial Public Class FluentModel
Protected Overrides Sub OnDatabaseOpen(ByVal backendConfiguration As _
Telerik.OpenAccess.BackendConfiguration, ByVal metadataContainer As _
Telerik.OpenAccess.Metadata.MetadataContainer)
metadataContainer.DefaultMapping.InheritanceStrategy = _
Telerik.OpenAccess.InheritanceStrategy.Horizontal
MyBase.OnDatabaseOpen(backendConfiguration, metadataContainer)
End Sub
End Class