【问题标题】:Automapper CreateMissingTypeMaps property WarningAutomapper CreateMissingTypeMaps 属性警告
【发布时间】:2016-10-11 12:12:35
【问题描述】:

我认为这是一个重复的问题,但我无法解决它。 这是我的地图。

UserProfileVM model = AutoMapper.Mapper.DynamicMap<UserProfileVM>(objUser);

但是这里AutoMapper 给出警告。

我尝试添加MapperConfiguration,但我不知道如何在DynamicMap&lt;&gt;() 中使用它。

var config = new MapperConfiguration(cfg => { cfg.CreateMissingTypeMaps = true; });

现在如何将我的 config 变量用于动态地图?

或者这些问题是否有任何全局设置,因为我在我的应用程序中多次使用映射器。

【问题讨论】:

    标签: c# asp.net-mvc automapper


    【解决方案1】:

    使用某种配置初始化静态AutoMapper(推荐给你展示的用法):

    Mapper.Initialize(cfg => cfg.CreateMissingTypeMaps = true);
    

    或者从配置中创建 AutoMapper 的实例:

    var config = new MapperConfiguration(cfg => { cfg.CreateMissingTypeMaps = true; });
    IMapper mapper = config.CreateMapper();
    

    AutoMapper Static and Instance API

    【讨论】:

    • 如果您选择Mapper.Initialize,您应该能够在静态 AutoMapper 上调用 DynamicMap,如示例中所示:UserProfileVM model = AutoMapper.Mapper.DynamicMap&lt;UserProfileVM&gt;(objUser);
    • 静态 API 现在在 AutoMapper 9.0 中已过时
    猜你喜欢
    • 2017-12-24
    • 2011-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    • 2021-09-22
    • 1970-01-01
    • 2020-01-11
    相关资源
    最近更新 更多