In one of my entities I need a special mapping which converts a delimited string (from the DB) to a Dictionary. Instead of using some dummy property I thought the more elegant way would be a custom mapper as described here
My problem is that no method from the mapper is ever called and NPOCO attempts to convert my db-string to a dictionary which obviously fails.
Maybe I misunderstand the mapper or am missing something. But can't explain why it doesn't work.
My Mapping (simplified)
public class MyEntityMap : Map<MyEntity>
{
public MyEntity()
{
Columns(x =>
{
x.Column(c => c.SpecialColumn).WithName("SpecialColumn");
}, true);
}
}
My Mapper (doesn't do much)
public class MyMapper : DefaultMapper
{
public override Func<object, object> GetFromDbConverter(MemberInfo destMemberInfo, Type sourceType)
{
return base.GetFromDbConverter(destMemberInfo, sourceType);
}
public override Func<object, object> GetFromDbConverter(Type destType, Type sourceType)
{
return base.GetFromDbConverter(destType, sourceType);
}
public override bool MapMemberToColumn(MemberInfo pi, ref string columnName, ref bool resultColumn)
{
return base.MapMemberToColumn(pi, ref columnName, ref resultColumn);
}
public override void GetTableInfo(Type t, TableInfo ti)
{
base.GetTableInfo(t, ti);
}
}
My datalayer (constructor)
protected SimpleDepot()
{
//SQL Server / MySQL
if (!mappingInitialized)
{
NPocoDatabaseFactory.Setup("connectionstring");
mappingInitialized = true;
}
Database = NPocoDatabaseFactory.DbFactory.GetDatabase();
Database.Mapper = new MyMapper();
PocoData = Database.PocoDataFactory.ForType(typeof(TEntity));
}
So everything seems in order at least to me. Any ideas what I'm missing. I'm currently using NPOCO 2.9.103 but I'm checking if I can update to v3
Ok, so I just upgraded to NPoco v3 and it went smoother than suspected (just had to change some small code parts to match breaking changes)
see https://github.com/schotime/NPoco/wiki/Version-3 for breaking changes.
Anyway: with v3 my mapper gets called. Maybe it was a bug in v2?
If you have the same problem with v2 consider upgrading to v3 (there are breaking changes which may or may not affect you)
I'm currently using v3.4.1