Using String Based API
This topic provides you information about the string based API. The Fluent Mapping API exposes the following extension methods from the Telerik.OpenAccess.Metadata.Fluent.Advanced namespace for property/field configuration. The common between all these methods is that they accept only string parameters.
- HasField - returns a property configuration object that allows you to configure a class field.
- HasMember - returns a property configuration object for a field/property pair.
- HasPrimitiveField - returns a property configuration object for a primitive field.
- HasPrimitiveMember - returns a property configuration object for a primitive field/property pair.
- HasStringField - returns a property configuration object for a string field.
- HasStringMember - returns a property configuration object for a string field/property pair.
- HasDateTimeField - returns a property configuration object for a DateTime field.
- HasDateTimeMember - returns a property configuration object for a DateTime field/property pair.
- HasAssociationField - returns a property configuration object for a navigation field. Use for configuring an association between private fields.
- HasAssociationMember - returns a property configuration object for a navigation field/property pair.
- WithOppositeField - specifies the opposite field for an association.
- WithOppositeMember - specifies the opposite property for an association.
All extension methods are located in the Telerik.OpenAccess.Metadata.Fluent.Advanced namespace.
Here is a sample FluentMetadataSource implementation demonstrating how to map the Address class using only string based methods.
public class FluentModelMetadataSource : FluentMetadataSource
{
protected override IList<MappingConfiguration> PrepareMapping()
{
List<MappingConfiguration> configurations = new List<MappingConfiguration>();
MappingConfiguration<Address> addressConfiguration = new MappingConfiguration<Address>();
addressConfiguration.HasPrimitiveMember( "id", "Id" ).IsIdentity( KeyGenerator.Autoinc ).
ToColumn( "AddressId" );
addressConfiguration.HasStringMember( "addressLine1", "AddressLine1" ).
ToColumn( "AddressLine" );
addressConfiguration.HasStringMember( "city", "City" ).ToColumn( "City" ).
IsNotNullable();
addressConfiguration.HasDateTimeMember( "modifiedDate", "ModifiedDate" ).
ToColumn( "ModifiedDate" ).
WithDataAccessKind( Telerik.OpenAccess.DataAccessKind.ReadOnly );
configurations.Add( addressConfiguration );
return configurations;
}
}
Public Class FluentModelMetadataSource
Inherits FluentMetadataSource
Protected Overrides Function PrepareMapping() As IList(Of MappingConfiguration)
Dim configurations As New List(Of MappingConfiguration)()
Dim addressConfiguration As New MappingConfiguration(Of Address)()
addressConfiguration.HasPrimitiveMember("_id", "Id").IsIdentity(KeyGenerator.Autoinc). _
ToColumn("AddressId")
addressConfiguration.HasStringMember("_addressLine1", "AddressLine1"). _
ToColumn("AddressLine")
addressConfiguration.HasStringMember("_city", "City").ToColumn("City").IsNotNullable()
addressConfiguration.HasDateTimeMember("_modifiedDate", "ModifiedDate").
ToColumn("ModifiedDate"). _
WithDataAccessKind(Telerik.OpenAccess.DataAccessKind.ReadOnly)
configurations.Add(addressConfiguration)
Return configurations
End Function
End Class
Address Class
public class Address
{
private int id;
public int Id
{
get { return id; }
set { id = value; }
}
private string addressLine1;
public string AddressLine1
{
get { return addressLine1; }
set { addressLine1 = value; }
}
private string city;
public string City
{
get { return city; }
set { city = value; }
}
private DateTime modifiedDate;
public DateTime ModifiedDate
{
get { return modifiedDate; }
set { modifiedDate = value; }
}
}
Public Class Address
Private _id As Integer
Public Property Id() As Integer
Get
Return _id
End Get
Set(ByVal value As Integer)
_id = value
End Set
End Property
Private _addressLine1 As String
Public Property AddressLine1() As String
Get
Return _addressLine1
End Get
Set(ByVal value As String)
_addressLine1 = value
End Set
End Property
Private _city As String
Public Property City() As String
Get
Return _city
End Get
Set(ByVal value As String)
_city = value
End Set
End Property
Private _modifiedDate As Date
Public Property ModifiedDate() As Date
Get
Return _modifiedDate
End Get
Set(ByVal value As Date)
_modifiedDate = value
End Set
End Property
End Class