我使用自动映射器来映射标准数据类型的类对象,即string,int,它工作正常,但现在我有多个自定义类的类,我正在努力将它映射到相同的类对象。
public class WebSyncSummaryEntity
{
public Web_AppFormsEntity AppForms { get; set; }
public Web_EBS_SyncEntity EBS_Sync { get; set; }
public Web_SyncAuditLogEntity SyncAuditLog { get; set; }
}
[DataContract]
public class WebSyncSummaryView
{
[DataMember]
public Web_AppForms AppForms { get; set; }
[DataMember]
public Web_EBS_Sync EBS_Sync { get; set; }
[DataMember]
public Web_SyncAuditLog SyncAuditLog { get; set; }
}
"Error mapping types.\r\n\r\nMapping types:\r\nWebSyncSummaryEntity -> WebSyncSummaryView\r\nApp.Entities.WebSyncSummaryEntity -> App.WebServices.DataContract.WebSyncSummaryView\r\n\r\nType Map configuration:\r\nWebSyncSummaryEntity -> WebSyncSummaryView\r\nApp.Entities.WebSyncSummaryEntity -> App.WebServices.DataContract.WebSyncSummaryView\r\n\r\nProperty:\r\nSyncAuditLog"}
Mapping types:
IList`1 -> IList`1
System.Collections.Generic.IList`1[[App.Entities.WebSyncSummaryEntity, App.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] -> System.Collections.Generic.IList`1[[App.WebServices.DataContract.WebSyncSummaryView, App.Services.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
public IList<WebSyncSummaryView> GetWebSyncSummary()
{
IList<WebSyncSummaryView> _WebSyncSummaryView = null;
IList<WebSyncSummaryEntity> _WebSyncSummaryEntity = _WebSyncCoreObject.GetWebSyncSummary();
if (_WebSyncSummaryEntity != null)
{
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<WebSyncSummaryEntity, WebSyncSummaryView>();
});
IMapper mapper = config.CreateMapper();
_WebSyncSummaryView = mapper.Map<IList<WebSyncSummaryEntity>, IList<WebSyncSummaryView>>(_WebSyncSummaryEntity);
}
return _WebSyncSummaryView;
}
答案 0 :(得分:1)
这样的配置:
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMissingTypeMaps = true; //your are missing this
cfg.CreateMap<WebSyncSummaryEntity, WebSyncSummaryView>();
});