Object hierarchy support in v3.0
Closed this issue · 3 comments
By looking at the source code it seems there is no support for object hierarchy and so I have a question regarding an eventual implementation of it.
We are using a discriminator property, which would serve as a way to differentiate between the records fetched and based on it, an object of a respective type to be used. Where do you think would be the most proper way to hook this logic, because by the looks of it, its all very tied. The MapperFactory is producing a concrete implementation of Mapper which cannot deal with this.
Would SqlFuManager.Config.CustomMappers.Register maybe be of use in the situation?
Do you plan any support for this? Can you provide any pointers?
Why do you mean by object hierarchy?
If I understood correctly, maybe QueryAndProcess
can help you
public class MyTableRow
{
public int Id {get;set;}
public string Data {get;set;}
public string Type {get;set;}
}
class BaseItem
{
}
class ItemA: BaseItem
{
}
var result=new List<BaseItem>();
db.QueryAndProcess<MyTableRow>(q=>q.Sql(sql,args),row=> {
switch(row.Type)
{
case "Type1": // map manually or using AutoMapper to ItemA
result.Add(itemA) ;
break;
//etc
}
return true; //to continue
})
Thank you for the response. What I meant with the question is for example:
A base entity with a couple of derived classes, and using table-per-hierarchy to be able to Select by base class but the mapper to instantiate proper classes based on a discriminator field. We have solved the problem using SqlFuManager.Config.CustomMappers.Register and it seems to be working.
@preslavnd can you share any implementation details? I'm looking to do the same thing.