Mapping Artificial Properties
Artificial properties are properties that extend the structure of a persistent class by adding new persistent fields during runtime. Artificial properties can be of any normal CLR type, their type can be another persistent class (artificial association) or a generic collection.
In this topic:
- Using the HasArtificialPrimitiveProperty method
- Using the HasArtificialStringProperty method
- Using the HasArtificialProperty method
- Using the HasArtificialAssociation and HasArtificialCollectionAssociation method
The MappingConfiguration class provides extension methods for working with artificial types. In order to use them, you need to use/import the Telerik.OpenAccess.Metadata.Fluent.Artificial namespace.
Using the HasArtificialPrimitiveProperty Extension Method
For the declaration of any primitive property such as int, double, bool, etc., the generic HasArtificialPrimitiveProperty<T> extension method should be used. The following example demonstrates how to use the HasArtificialPrimitiveProperty<T> extension method.
MappingConfiguration productConfiguration = new MappingConfiguration( "Product", "ProductNamespace" );
productConfiguration.HasArtificialPrimitiveProperty<decimal>( "Price" );
productConfiguration.HasArtificialPrimitiveProperty<int>( "Id" ).IsIdentity( KeyGenerator.Autoinc );
Dim productConfiguration As New MappingConfiguration("Product", "ProductNamespace")
productConfiguration.HasArtificialPrimitiveProperty(Of Decimal)("Price")
productConfiguration.HasArtificialPrimitiveProperty(Of Integer)("Id").IsIdentity(KeyGenerator.Autoinc)
Alternatively, you can use the non-generic HasArtificialPrimitiveProperty in the following manner:
productConfiguration.HasArtificialPrimitiveProperty("Id", typeof(int));
productConfiguration.HasArtificialPrimitiveProperty("Id", GetType(Integer))
Using the HasArtificialStringProperty Extension Method
Use the HasArtificialStringProperty extension method, when you want to define a new artificial string property. The following example demonstrates how to use the HasArtificialStringProperty method.
MappingConfiguration categoryConfiguration = new MappingConfiguration("Category", "CategoryNamespace");
categoryConfiguration.HasArtificialStringProperty("CategoryName");
Dim categoryConfiguration As New MappingConfiguration("Category", "CategoryNamespace")
categoryConfiguration.HasArtificialStringProperty("CategoryName")
Using the HasArtificialProperty Extension Method
The HasArtificialProperty<T> method should be used only when the artificial property could not be declared by the other methods exposed by the Fluent Mapping API. The following example demonstrates how to use the HasArtificialProperty<T> method.
MappingConfiguration categoryConfiguration = new MappingConfiguration("Category", "CategoryNamespace");
categoryConfiguration.HasArtificialProperty<byte[]>("CategoryImage");
Dim categoryConfiguration As New MappingConfiguration("Category", "CategoryNamespace")
categoryConfiguration.HasArtificialProperty(Of Byte())("CategoryImage")
Alternatively you can use the non-generic HasArtificialProperty in the following manner:
productConfiguration.HasArtificialProperty("CategoryImage", typeof(byte[]));
productConfiguration.HasArtificialProperty("CategoryImage", GetType(Byte()))
Using the HasArtificialAssociation and HasArtificialCollectionAssociation Extension Methods
For more information please refer to the Artificial Associations section.