I am using dapper extensions and have a question about the class mapper. Unfortunately most of my tables need some mapping done to them such as different schemas etc.
So I find I am typically doing a lot of swapping out the DefaultMapper as per below:
public Hierarchies HierarchyGetByName(string aName)
{
Hierarchies result;
using (SqlConnection cn = GetSqlConnection())
{
cn.Open();
Type currModelMapper = DapperExtensions.DapperExtensions.DefaultMapper;
try
{
DapperExtensions.DapperExtensions.DefaultMapper = typeof(HierarchiesMapper);
IFieldPredicate predicate = Predicates.Field<Hierarchies>(f => f.Name, Operator.Eq, aName);
result = cn.GetList<Hierarchies>(predicate).FirstOrDefault();
}
finally
{
DapperExtensions.DapperExtensions.DefaultMapper = currModelMapper;
}
cn.Close();
}
return result;
}
If I access 2 tables then I have to do this twice for instance.
Is there a way to add all the mapper classes at once to say a collection and depending on the table being accessed the correct one is chosen?