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 you Locations module: Implement the OpenAccess data provider, you need to implement the fluent mappings to map your model classes to database tables. To use the mappings in the data provider, you must return an instance of the LocationsFluentMetadataSource in the GetMetaDataSourcemethod of the provider.
To implement the fluent mappings for your data provider, you must create the LocationsFluentMapping and the LocationsFluentMetadataSource classes.
The LocationsFluentMapping class defines the mapping for the LocationItem model class. To create the class:
public
class
LocationsFluentMapping : OpenAccessFluentMappingBase
{
}
LocationsFluentMapping(IDatabaseMappingContext context)
:
base
(context)
To implement it, you must override the GetMappings abstract method. In the method, create the required mappings. Use the following code for the method:
override
IList<MappingConfiguration> GetMapping()
// initialize and return mappings
var mappings =
new
List<MappingConfiguration>();
MapItem(mappings);
MapUrlData(mappings);
return
mappings;
private
void
MapItem(IList<MappingConfiguration> mappings)
// initialize mapping
var itemMapping =
MappingConfiguration<LocationItem>();
itemMapping.HasProperty(p => p.Id).IsIdentity();
itemMapping.MapType(p =>
{ }).ToTable(
"sf_locations"
);
// add properties
itemMapping.HasProperty(p => p.Address);
itemMapping.HasProperty(p => p.City);
itemMapping.HasProperty(p => p.Region).IsNullable();
itemMapping.HasProperty(p => p.PostalCode);
itemMapping.HasProperty(p => p.Country);
// map urls table association
itemMapping.HasAssociation(p => p.Urls).WithOppositeMember(
"parent"
,
"Parent"
).ToColumn(
"content_id"
).IsDependent().IsManaged();
mappings.Add(itemMapping);
MapUrlData(IList<MappingConfiguration> mappings)
// map the Url data type
var urlDataMapping =
MappingConfiguration<LocationItemUrlData>();
urlDataMapping.MapType(p =>
{ }).Inheritance(InheritanceStrategy.Flat).ToTable(
"sf_url_data"
mappings.Add(urlDataMapping);
The LocationsFluentMetadataSource class wraps the mappings and exposes them to the OpenAccess data provider. To create the class, perform the following:
LocationsFluentMetadataSource : ContentBaseMetadataSource
LocationsFluentMetadataSource()
(
null
)
LocationsFluentMetadataSource(IDatabaseMappingContext context)
protected
IList<IOpenAccessFluentMapping> BuildCustomMappings()
var sitefinityMappings =
.BuildCustomMappings();
sitefinityMappings.Add(
LocationsFluentMapping(
this
.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