I have “table inheritance” in my DB (where descendants reference base with foreign key) and use Linq To Sql as my DAL:
[Table]
class Document {
[Column]public int ID { get; set; }
[Column]public int DocTypeID { get; set; }
[Association]public Application Application { get; set; }
}
[Table]
class Application {
[Column]public int ID { get; set; }
[Column]public string AppType { get; set; }
[Association]public Document Document {get;set}
}
Since L2S does not support multi-table inheritance Application is not inherited from Document. However, in my entity classes i do want inheritance:
class DocumentBase {
public int ID { get; set; }
public int DocTypeID { get; set; }
}
class MyApplication : DocumentBase {
public string AppType { get; set; }
}
Now i’m creating the mappings:
Mapper.CreateMap<Document, DocumentBase>();
Mapper.CreateMap<Application, MyApplication>();
But AutoMapper complains about base properties in MyApplication not mapped. I don’t want to duplicate base properties in MyApplication map (too many descendants from DocumentBase). I found few posts suggesting custom ITypeConverter but don’t understand how to apply it to my scenario. What do i do?
Found this solution which also suffers from
AssertConfigurationIsValid()complaining about base properties not mapped but slightly modified it:Now it can be chained to each
DocumentBasedescendant map:and
AssertConfigurationIsValid()is happy.