i never use auto mapper but hard many people use it to map two different object.i was reading few code snippet & article that showed how we can use auto mapper to map datatable data to Person entity classes.
i really did not know that auto mapper can be used to populate entity classes from datatable data.
here i got a guide line like
using (IDataReader dr = DatabaseContext.ExecuteReader(command))
{
if (dr.HasRows)
{
AutoMapper.Mapper.CreateMap<IDataReader, ProductModel>();
return AutoMapper.Mapper.Map<IDataReader, IList<ProductModel>>(dr);
}
return null;
}
http://www.geekytidbits.com/automapper-with-datatables/
i saw few people use CreateMap() function and few use DynamicMap()
. so i like to know what is the difference between this two function?
when we should use use CreateMap() function & when we should use use DynamicMap() function ? if possible please explain with example code & situation like when we should use one.
public class Person {
public string First_Name { get; set; }
public string Last_Name { get; set; }
public string User_Name { get; set; }
}
List<Person> people = AutoMapper.Mapper.DynamicMap<IDataReader, List<Person>>(
sourceDataTable.CreateDataReader());
just we should use DynamicMap() function to write one line less code ? because when we use CreateMap() function when we need to say name of two mapping object but when we use DynamicMap() then in one line we can do all. did i understand properly or the actual things or purpose of DynamicMap() function is different?
another issue is suppose when my entity classes property name is different and data table column name is different then how we can populate my entity class from data table?
suppose if data type is different then how to handle the situation ? data table column type is int but entity class field type is long or double....so how we can cast and store data?
please let me know whatever i asked here with code sample if possible. thanks.