A mapper class that is used to map the class property into its equivalent column in the database. This class is used as an alternative to Map attribute.
Below are the methods available from this class.
Add- adds a mapping between the class property and database column.
Clear- clears all the class properties and database columns mappings.
Get- gets the mapped name of the class property.
Remove- removes the exising mapping between the class property and database column.
You should use this class if you do not like to use the Map attribute. Usually, the purpose of the usability is to make sure that the model is attribute-free and is not bound to a specific ORM.
How to Use?
To add a mapping, simply call the
PropertyMapper.Add<Customer>(c => c.FirstName, "[FName]", true); PropertyMapper.Add<Customer>(c => c.LastName, "[LName]", true); PropertyMapper.Add<Customer>(c => c.DateOfBirth, "[DOB]", true);
An exception will be thrown if the mapping is already exists and you passed a
falsevalue in the
To get the mapping, use the
var mappedName = PropertyMapper.Get<Customer>(c => c.FirstName);
Please consider to always use the PropertyMappedNameCache class when extracting the mapped property name.
To remove the mapping, use the
PropertyMapper.Remove<Customer>(c => c.FirstName);