[DataContract]
public class SupplierView : BaseView
{
[DataMember]
Public int SupplierId { get; set; }
[DataMember]
Public ApprovedSupplierView approvedSupplier { get; set; }
[DataMember]
Public AdHocSupplierView adhocsupplier { get; set; }
//other fields...
}
[DataContract]
public class ContextSupplierView : SupplierView //Working
{
[DataMember]
Public int SupplierId { get; set; }
//New fields added
[DataMember]
Public ContextApprovedSupplierView contextApprovedSupplier { get; set; }
[DataMember]
Public ContextAdHocSupplierView contextAdhocsupplier { get; set; }
//other fields...
}
public class ApprovedSupplierView : BaseView
{
[DataMember]
Public string Name { get; set; }
[DataMember]
Public string Phone { get; set; }
[DataContract]
public class ContextSupplierView : SupplierView //Not working
{
[DataMember]
Public int SupplierId { get; set; }
[DataMember]
Public new ContextApprovedSupplierView approvedSupplier { get; set; }
[DataMember]
Public new ContextAdHocSupplierView adhocsupplier { get; set; }
//other fields...
}
[DataContract]
public class ContextApprovedSupplierView : ApprovedSupplierView
{
[DataMember]
Public string ContextDescription { get; set; }
SupplierView supplierObject = new SupplierView(Linq populates this correctly);
Mapper.CreateMap<SupplierView, ContextSupplierView>();
claimContext.Supplier = Mapper.Map<ContextSupplierView>(supplierObject);
我有一個已經得到供應商和嵌套類型從數據庫中的一個項目,但我該如何使用automapper一切複製到其中有ContextApprovedSupplier approvedSupplier和ContextAdHocSupplier一個ContextSupplier adHocSupplier但是,這給出:automapper:映射覆雜的源類tocomplex派生類
缺少類型映射配置或不支持的映射。
映射類型:ApprovedSupplierView - > ContextApprovedSupplierView TotalSystemsPlc.Bluescape.Claims.DataContracts.Views.ProjectLoadViews.ApprovedSupplierView - > TotalSystemsPlc.Bluescape.Claims.DataContracts.Views.ContextViews.ContextApprovedSupplierView
目標路徑: ContextSupplierView .ApprovedSupplier.ApprovedSupplier
來源值: TotalSystemsPlc.Bluescape.Claims.DataContracts.Views.ProjectLoadViews.ApprovedSupplierView
如果我創建新字段contextApprovedSupplier和contextAdhocsupplier,它會自動填充ApprovedSupplier和Adhocsupplier,它可以單獨映射,但我寧願在一個命令中完成所有操作。 任何幫助將得到很好的收到,因爲我一直在嘗試幾個小時來做到這一點!
編輯:道歉,請現在找到正確的層次!
什麼是'SupplierView'和'ContextSupplierView'? –
Shoudn't'ContextSupplier'是從'Supplier'派生的嗎?如果沒有,則提供聲明隱藏屬性的'Base'類'approvedSupplier'' adhocsupplier' – Rafal
您可以嘗試添加映射:'Mapper.CreateMap()'但在這種情況下您的視圖不應該返回'ContextApprovedSupplierView '? –
Rafal