【问题标题】:Why am I getting "Missing type map configuration or unsupported mapping" error?为什么我收到“缺少类型映射配置或不支持的映射”错误?
【发布时间】:2014-03-20 15:45:18
【问题描述】:

我无法理解这个错误。我即将加入另一个开发人员项目,他使用提供的代码来检索几个报告和所有功能,但是当我创建类似的报告时,我一直在标题中收到错误。

要使此映射正常工作,需要在哪里以及需要什么。 请告知是否需要更多代码。 另请注意,它是一个 ASP.NET MVC 3 应用程序

控制器....

    case ReportType.BS_Report:
            {
                model.BSReport = "Company name";

                var records = _docsRepo.PaginatedBS_Reports(model.BSReport,
                                                                            model.From,
                                                                            model.To,
                                                                            currentPageIndex,
                                                                            pageSize,
                                                                            out totalRecords);

                var TimeRec = Mapper.Map<IList<BS_Report>, IList<BSModel>>(records);

                var TimeRecdModel = TimeRec.ToReportPagedList(currentPageIndex,
                                                                            pageSize,
                                                                            model,
                                                                            totalRecords);

                return PartialView("BS_Report", TimeRecdModel);
            }

一切正常,直到它到达这条线......

   var TimeRec = Mapper.Map<IList<BS_Report>, IList<BSModel>>(records);

BS_Report 类...

     public class BS_Report : ReportBase
{
    public int Id { get; set; }
    public string EquipmentID { get; set; }
    public string EquipmentDescription { get; set; }
    public DateTime? CreatedOn { get; set; }
    public string CustomerName { get; set; }
}

BSModel....

      public class BSModel : ReportBaseModel
{

    public int Id { get; set; }
    public string EquipmentID { get; set; }
    public string EquipmentDescription { get; set; }
    public DateTime? CreatedOn { get; set; }
    public string CustomerName { get; set; }
 }

其他报告案例使用完全相同的代码...

     case ReportType.Full_Report:
            {
                var records = _docsRepo.PaginatedFullReportReports(model.ReportedOn,
                                                                            model.From,
                                                                            model.To,
                                                                            currentPageIndex,
                                                                            pageSize,
                                                                            out totalRecords);

                var TimeRecord = Mapper.Map<IList<FullReport>, IList<FullReportModel>>(records);

                var TimeRecordModel = TimeRecord.ToReportPagedList(currentPageIndex,
                                                                            pageSize,
                                                                            model,
                                                                            totalRecords);

                return PartialView("FullReport", TimeRecordModel);
            }

【问题讨论】:

  • 你的基类是什么样的?
  • 你能给我们完整的错误信息吗?通常它还会告诉您哪些特定的映射操作失败了。
  • 报告库为空。 ReportBaseMOdel,有一个属性 - public string CustomerName {get;set;}
  • 缺少类型映射配置或不支持的映射。映射类型:BS_Report -> BSModel Tracker.Persistence.Reports.BS_Report -> Tracker.ViewModels.ReportModels.BSModel 目标路径:IList`1[0] 源值:Tracker.Persistence.Reports.BS_Report

标签: c# asp.net-mvc-3 automapper


【解决方案1】:

您可能需要为您的新报告“创建”一个映射。在代码库中搜索对“CreateMap”的一些调用,这些调用对以前的开发人员使用的任何报告类型进行操作。您可能需要为您的 BS_Report 类型创建一个。

【讨论】:

  • 我将更新代码以显示以前的开发人员是如何编写它的(相同),所以我不确定任何“createMap”可能在哪里。我设置了断点,但所有程序在该行代码上为工作报告所做的所有程序都是挂起几秒钟然后继续。
  • CreateMap 很可能位于仅在应用程序启动时调用的代码段中。从 global.asax.cs 文件中的 Application_OnStart 开始,看看那里是否有希望。您必须使用 CreateMap 为您计划稍后在代码中映射的每种类型注册一个映射。我认为它必须在某个地方。
  • 根据您的编辑,您应该在代码库的某处找到一些参考,例如 Automapper.CreateMap。或者 AutoMapper.CreateMap,IList>.
  • 知道了,好人,我确实失踪了,Mapper.CreateMap();来自 ViewModelProfile 类中的 Configure 方法。
猜你喜欢
  • 1970-01-01
  • 2013-01-18
  • 2015-06-27
  • 1970-01-01
  • 1970-01-01
  • 2019-03-01
  • 2017-04-16
  • 2015-09-22
  • 1970-01-01
相关资源
最近更新 更多