Telerik OpenAccess ORM

Telerik OpenAccess ORM Send comments on this topic.
Mapping Artificial Properties
Programmer's Guide > Developer's Guide > Code-Only Mapping > Artificial Types > Mapping Artificial Properties

Glossary Item Box

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:

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.

C# Copy Code
MappingConfiguration productConfiguration = new MappingConfiguration( "Product", "ProductNamespace" );
productConfiguration.HasArtificialPrimitiveProperty<
decimal>( "Price" );
productConfiguration.HasArtificialPrimitiveProperty<
int>( "Id" ).IsIdentity( KeyGenerator.Autoinc );
VB.NET Copy Code
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:

C# Copy Code
productConfiguration.HasArtificialPrimitiveProperty("Id", typeof(int));
VB.NET Copy Code
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.

C# Copy Code
MappingConfiguration categoryConfiguration = new MappingConfiguration("Category", "CategoryNamespace");
categoryConfiguration.HasArtificialStringProperty(
"CategoryName");
VB.NET Copy Code
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.

C# Copy Code
MappingConfiguration categoryConfiguration = new MappingConfiguration("Category", "CategoryNamespace");
categoryConfiguration.HasArtificialProperty<
byte[]>("CategoryImage");
VB.NET Copy Code
Dim categoryConfiguration As New MappingConfiguration("Category", "CategoryNamespace")
categoryConfiguration.HasArtificialProperty(Of Byte())("CategoryImage")

Alternatively you can use the non-generic HasArtificialProperty in the following manner:

C# Copy Code
productConfiguration.HasArtificialProperty("CategoryImage", typeof(byte[]));
VB.NET Copy Code
productConfiguration.HasArtificialProperty("CategoryImage", GetType(Byte()))

 

Using the HasArtificialAssociation and HasArtificialCollectionAssociation Extension Methods

For more information please refer to the Artificial Associations section.