Home » Documentation » Extending » Extending a data mapper
A Scensum data mapper is an object responsible for mapping data from one or more database tables onto a business object. The mapping process involves taking a data reader object, getting an instance of the business object from the IoC container, mapping the data reader values to the properties of the object, and returning a fully populated business object.
There is a 1-to-1 relationship between a business object and its data mapper. In some cases the data mapper extends a generic mapper, as in the cases of the ProductRecordDataMapper and ProductViewDataMapper. The objects being mapped in these data mappers, namely IProductRecord and IProductView, both extend IProduct and their corresponding data mappers both extend a common, generic data mapper, ProductDataMapper. Both generic and non-generic data mappers can be customized according to your requirements.
Create class
Extend the appropriate data mapper.
C#
public class ExtendedProductDataMapper : ProductDataMapper<IProduct>
C#
public class ExtendedPriceListItemDataMapper : PriceListItemDataMapper
Override the data mapper's Create method
Call base.Create() to map the data of the base object.
C#
protected override IProduct Create()
{
IExtendedProduct extendedProduct = (IExtendedProduct)base.Create();
extendedProduct.NewProperty = MapValue<string>(_newPropertyColumnIndex);
return extendedproduct;
}
Modify the IoC settings file
Data mapper instances are managed by the IoC container. To get the IoC container to create an instance of your extended data mapper, the type definition in the IoC settings file needs to be modified.
XML
<component
id="ProductDataMapper"
lifestyle="transient"
service="Litium.Framework.DataMapper.DataMapperBase`1[[Litium.Scensum.Product.Contract.BusinessObject.IProduct,
"Litium.Scensum.Product.Contract]], Litium.Framework.DataMapper"
type="YourProject.ExtendedProductDataMapper, YourProject" />