[Context是一个ASP.NET MVC Web应用程序] 我最近将我的AutoMapper引用升级到4.2.1,并且有各种各样的适应性。它没有降低我的生产应用程序,客户不满意。希望有人可以提供帮助。
我修复了因Mapper.AssertConfigurationIsValid();
而返回的所有错误,所以现在不会产生错误。但是,在转弯时,当我拨打Mapper.Map<ConsumeInventoryViewModel>(pullListDetailViewModel);
时,我收到错误:
[AutoMapperMappingException: Missing type map configuration or unsupported mapping.
Mapping types:
PullListDetailViewModel -> ConsumeInventoryViewModel
OTIS.AppServ.InventoryMgmt.ViewModels.PullListDetailViewModel -> OTIS.AppServ.InventoryMgmt.ViewModels.ConsumeInventoryViewModel
Destination path:
ConsumeInventoryViewModel
Source value:
OTIS.AppServ.InventoryMgmt.ViewModels.PullListDetailViewModel]
重要的是,我得到了我所拥有和调用的所有映射的错误,而不仅仅是一个...我应该说多重...我还没有尝试过所有,但对于那些我有的调用它会产生错误。
以下是一些细节:
模特:
public class AutoPullViewModel
{
public bool autoLocateOnPull { get; set; }
}
public class PullListDetailViewModel : AutoPullViewModel
{
public int? AllocatedInventoryId { get; set; }
[Display(Name = "Work Release")]
public int WorkReleaseHeaderId { get; set; }
public OrderHeader.OrderTypes OrderTypeEnum { get; set; }
[Display(Name = "Order/Job")]
public int? OrderId { get; set; }
[Display(Name = "Part Nbr")]
public int? OrderDetailId { get; set; }
[Display(Name = "Work Order")]
public int? WorkOrderId { get; set; }
public int? WorkOrderDetailId { get; set; }
public bool IsInventoriedItem { get; set; }
[Display(Name = "Container")]
public int? InventoryContainerHeaderId { get; set; }
public string OriginalContainerLocationBarcode { get; set; }
public int? LocationInventoryId {get; set;}
public string RequiredLocationBarcode { get; set; }
[Display(Name = "Location")]
public string LocationDescription { get; set; }
public int ItemId { get; set; }
public string SKU { get; set; }
public string RequiredItemBarcode { get; set; }
[Display(Name = "Item/Material")]
public string ItemDescription { get; set; }
public string ItemImageURL { get; set; }
[Display(Name = "Qty")]
[DisplayFormat(DataFormatString = "{0:N1}")]
public decimal RequiredQuantity { get; set; }
public string QuantityDescription { get; set; }
public string QuantityUOM { get; set; }
}
//Direct user to location for selected material
public class ConsumeInventoryViewModel : PullListDetailViewModel
{
[Display(Name = "Scan Location")]
public string ScannedLocationBarcode { get; set; }
[Display(Name = "Scan Item")]
public string ScannedItemBarcode { get; set; }
[Display(Name = "Scan Container")]
public int? ScannedContainerId { get; set; }
[Required]
[Display(Name = "Act Qty")]
[UIHint("TextBoxFor_75w")]
public decimal? ConfirmedQty { get; set; }
[Display(Name = "Only Remnants?")]
public bool Remnant { get; set; }
}
在Global.asax Application_Start
protected void Application_Start()
{
...
AutoMapperConfiguration.Configure();
}
静态配置器:
public static class AutoMapperConfiguration
{
public static void Configure()
{
//see https://github.com/AutoMapper/AutoMapper/wiki/Configuration
Mapper.Initialize(cfg =>
{
cfg.CreateMap<PullListDetailViewModel, ConsumeInventoryViewModel>()
.ForMember(dest => dest.ScannedLocationBarcode, option => option.Ignore())
.ForMember(dest => dest.ScannedItemBarcode, option => option.Ignore())
.ForMember(dest => dest.ScannedContainerId, option => option.Ignore())
.ForMember(dest => dest.ConfirmedQty, option => option.Ignore())
.ForMember(dest => dest.Remnant, option => option.Ignore())
;
});
Mapper.AssertConfigurationIsValid();
}
}
最后运行时调用map:
var consumeInventoryViewModel = Mapper.Map<ConsumeInventoryViewModel>(pullListDetailViewModel);
与developer一样,我在IIS中重新启动网站后(我可以调试并确保正在点击配置和验证),第一次调用运行时映射会起作用,但所有后续调用都会失败。
任何人都有任何指示/想法?