• 报错:Missing type map configuration or unsupported mapping


    报错:Missing type map configuration or unsupported mapping

    □ 背景

    当把View Model转换成Domain Model保存的时候,发生在AutoMapper的错误。

     

    □ 分析

    1、在派生于AutoMapper的Profile的类中已经建立映射:
    Mapper.CreateMap<SomeDomainModel, SomeViewModel>();

     

    2、也已经初始化派生于Profile的类:

        public static class AutoMapperConfiguration
        {
            public static void Configure()
            {
                Mapper.Initialize(x => x.AddProfile<SomeProfile>());
     
            }
        }

     

    3、在全局中也注册了:

            protected void Application_Start()
            {
                //配置映射
                AutoMapperConfiguration.Configure();
            }    

     

    4、单元测试也通过:

        [TestClass]
        public class AutoMapperConfigurationTester
        {
            [TestMethod]
            public void TestMethod1()
            {
                AutoMapperConfiguration.Configure();
                Mapper.AssertConfigurationIsValid();
            }
        }

    □ 解决方法

    在实际映射的时候,把AutoMapper.Mapper.Map<Source, Destination>换成AutoMapper.Mapper.DynamicMap<Source, Destination>

    DomainModel someDomainModel = AutoMapper.Mapper.Map<ViewModel, DomainModel>(someViewModel);

    改成:

    DomainModel someDomainModel = AutoMapper.Mapper.DynamicMap<ViewModel, DomainModel>(someViewModel);    
  • 相关阅读:
    高性能网站优化-确保异步加载脚本时保持执行顺序
    sublime安装和汉化
    解决IE6下a标签的onclick事件里的超链接不跳转问题
    C++大数据处理
    HDRtools-OpenExr
    Effective C++学习进阶版
    我的算法学习之路
    一个应届计算机毕业生的2012求职之路
    存储器管理
    程序员的自我修养——操作系统篇
  • 原文地址:https://www.cnblogs.com/darrenji/p/3597547.html
Copyright © 2020-2023  润新知