AutoMapper.Mapper 不包含 CreateMap 的定义 [英] AutoMapper.Mapper does not contain definition for CreateMap

查看:27
本文介绍了AutoMapper.Mapper 不包含 CreateMap 的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个基本问题,但想知道我没有得到 AutoMapper.Mapper.CreateMap 方法.

This might be a basic question but wondering I am not getting AutoMapper.Mapper.CreateMap method.

我是否使用了错误的 AutoMapper 参考/包?谢谢

Am I using wrong AutoMapper reference/package? Thanks

推荐答案

CreateMap 方法的静态版本在 4.2 中被弃用,然后在 5.0 版中从 API 中删除.Jimmy Bogard 在this博文.

The static version of the CreateMap method was deprecated in 4.2, then removed from the API in version 5.0. Jimmy Bogard talks about this in more detail in this blog post.

映射的新技术是非静态的,像这样(代码来自帖子):

The new technique for mapping is non-static, like this (code is from the post):

var config = new MapperConfiguration(cfg => {
    cfg.CreateMap<Source, Dest>();
});

IMapper mapper = config.CreateMapper();
var source = new Source();
var dest = mapper.Map<Source, Dest>(source);

这篇关于AutoMapper.Mapper 不包含 CreateMap 的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆