IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
After Custom Products module: Implement the OpenAccess data provider, you implement the fluent mappings that map your model classes to database tables. To implement the fluent mappings for your data provider, you must create the following classes:
To use the mappings in the data provider, you must return an instance of the ProdusFluentMetadataSource in the GetMetaDataSource method of the provider.
The ProductsFluentMapping class defines the mapping for the ProductItem model class. To create the class:
using
System.Collections.Generic;
Telerik.OpenAccess;
Telerik.OpenAccess.Metadata;
Telerik.OpenAccess.Metadata.Fluent;
Telerik.OpenAccess.Metadata.Fluent.Advanced;
Telerik.Sitefinity;
Telerik.Sitefinity.Model;
public
class
ProductsFluentMapping : OpenAccessFluentMappingBase
{
}
ProductsFluentMapping(IDatabaseMappingContext context)
:
base
(context)
To implement the class, you must override the GetMapping abstract method. In the method, you create the mappings. Following is the code for the method:
override
IList<MappingConfiguration> GetMapping()
var mappings =
new
List<MappingConfiguration>();
MapItem(mappings);
MapUrlData(mappings);
return
mappings;
private
void
MapItem(IList<MappingConfiguration> mappings)
var itemMapping =
MappingConfiguration<ProductItem>();
itemMapping.HasProperty(p => p.Id).IsIdentity();
itemMapping.MapType(p =>
{ }).ToTable(
"custom_products"
);
itemMapping.HasProperty(p => p.Price);
itemMapping.HasProperty(p => p.QuantityInStock);
itemMapping.HasAssociation<Telerik.Sitefinity.Security.Model.Permission>(p => p.Permissions);
itemMapping.HasProperty(p => p.InheritsPermissions);
itemMapping.HasProperty(p => p.CanInheritPermissions);
itemMapping.HasAssociation(p => p.Urls).WithOppositeMember(
"parent"
,
"Parent"
).ToColumn(
"content_id"
).IsDependent().IsManaged();
//map language data & published translations
CommonFluentMapping.MapILifecycleDataItemFields<ProductItem>(itemMapping,
this
.Context);
mappings.Add(itemMapping);
MapUrlData(IList<MappingConfiguration> mappings)
var urlDataMapping =
MappingConfiguration<ProductItemUrlData>();
urlDataMapping.MapType(p =>
{ }).Inheritance(InheritanceStrategy.Flat).ToTable(
"sf_url_data"
mappings.Add(urlDataMapping);
The ProductsFluentMetadataSource class wraps the mappings and exposes them to the OpenAccess data provider. To create the class:
Telerik.Sitefinity.Modules.GenericContent.Data;
ProductsFluentMetadataSource : ContentBaseMetadataSource
ProductsFluentMetadataSource()
(
null
)
{ }
ProductsFluentMetadataSource(IDatabaseMappingContext context)
In the method, create an instance of the ProductsFluentMapping class and add the instance to the default set of mappings. Following is the code for the method:
protected
IList<IOpenAccessFluentMapping> BuildCustomMappings()
var sitefinityMappings =
.BuildCustomMappings();
sitefinityMappings.Add(
ProductsFluentMapping(
.Context));
sitefinityMappings;
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important