非標準繼承映射我在我的DB(其中後人引用與外鍵基地)「表繼承」,使用的LINQ to SQL作爲我DAL:與AutoMapper
[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}
}
因爲L2S不支持多表繼承Application
不是從Document
繼承。然而,在我的實體類我也想繼承:
class DocumentBase {
public int ID { get; set; }
public int DocTypeID { get; set; }
}
class MyApplication : DocumentBase {
public string AppType { get; set; }
}
現在,我創建的映射:
Mapper.CreateMap<Document, DocumentBase>();
Mapper.CreateMap<Application, MyApplication>();
但AutoMapper抱怨沒有映射在MyApplication
基本屬性。我不想在MyApplication
地圖中複製基本屬性(太多的DocumentBase
後代)。我發現很少有帖子建議自定義ITypeConverter
,但不明白如何將其應用於我的場景。我該怎麼辦?
非常有趣,我以前沒見過 – boca