我正在开发一个 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();
}
}
最后是对地图的运行时调用:
var consumeInventoryViewModel = Mapper.Map<ConsumeInventoryViewModel>(pullListDetailViewModel);
像其他帖子一样,在我在 IIS 中重新启动网站后(我可以调试并确保正在命中配置和验证,对运行时映射的第一次调用有效,但所有后续调用均失败。
有人有任何指示/想法吗?