-1
我需要将DTO对象映射到我的webservice将接受的对象。如何使用AutoMapper从强类型列表映射到类型的数组列表:对象
DTO对象:
public class TerminationCause
{
// other properties...
public List<TerminationCauseServicePurchase> TerminationCauseServicePurchase { get; set; }
public TerminationCause()
{
TerminationCauseServicePurchase = new List<TerminationCauseServicePurchase>();
}
}
Web服务对象:
public partial class TerminationCause
{
public object[] TerminationCauseServicePurchase { get; set; }
// other properties...
}
所有的 “其他属性” 具有相同的名称和TerminationCauseServicePurchase类是相同的。问题是TerminationCauseServicePurchase字段没有被映射。
这里是映射:
Mapper.CreateMap<DTO.TerminationCause, ExternalUdbudsportal.TerminationCause>();
Mapper.CreateMap<DTO.TerminationCauseServicePurchase, ExternalUdbudsportal.TerminationCauseServicePurchase>();
TerminationCause对象被正确映射,但它的内部列表“TerminationCauseServicePurchase”仍然是相同的类型(DTO.TerminationCauseServicePurchase而不是ExternalUdbudsportal.TerminationCauseServicePurchase),使Web服务不接受。
地图方法:
upEkst.TerminationCause tmpTC = Mapper.Map<DTO.TerminationCause, upEkst.TerminationCause>(tc);
为什么使用'object []'而不是接口数组?我相信要让AutoMapper处理一个对象[]会很困难,但也许不会。 – TyCobb 2014-09-29 15:32:10
这是Web服务的WSDL向我提供的内容。改变它是一个好主意吗?有没有解决方法? – Kenci 2014-09-29 15:32:44
@TyCobb我的想法正是如此。 – 2014-09-29 15:33:00