英文:
AutoMapper Version 9.0.0 - No ConfigureMap() Method on IMappingOperationOptions
问题
我正在将Visual Studio 2019解决方案的项目从AutoMapper版本8.0.0升级到版本9.0.0。代码中有许多地方调用ConfigureMap()方法。构建输出中的错误信息如下:
> IMappingOperationOptions<TSource, TDestination> does not contain
> a definition for ConfigureMap and no accessible extension method
> ConfigureMap...
以下是当前代码的示例:
Mapper.Map(TSource, TDestination, opt => opt.ConfureMap());
Mapper.Map(TSource, TDestination, opt => opt.ConfigureMap().ForMember(dest => dest.someBool, m => m.MapFrom(src => src.someBoolVal));
我查看了AutoMapper从8.0.0升级到9.0.0的文档,没有看到ConfigureMap()方法被弃用的提及。然而,在搜索Visual Studio的对象浏览器时,它并未出现。
如果有人可以分享代码,以在9.0.0中实现相同的功能,我将不胜感激。
英文:
I'm upgrading a Visual Studio 2019 solution's projects from AutoMapper version 8.0.0 to version 9.0.0. There are a number of places in the code that are calling a ConfigureMap() method. Errors in the build output state:
> IMappingOperationOptions<TSource, TDestination> does not contain
> a definition for ConfigureMap and no accessible extension method
> ConfigureMap...
Here are examples of what the current code looks like:
Mapper.Map(TSource, TDestination, opt => opt.ConfureMap());
Mapper.Map(TSource, TDestination, opt => opt.ConfigureMap().ForMember(dest => dest.someBool, m => m.MapFrom(src => src.someBoolVal));
I've looked at AutoMapper's documentation for upgrading from 8.0.0 to 9.0.0 and see no mention of the ConfigureMap() method being deprecated. However, it's not appearing when I search VS's Object Browser.
I would be most appreciative if anyone can share code for how to accomplish the same functionality in 9.0.0.
答案1
得分: 3
我遇到了相同的问题(IMappingOperationOptions不包含ConfigureMap的定义),我用了不同的方法解决了。
//步骤1. 创建一个MapperConfiguration
var customMapConfig = new MapperConfiguration(cfg =>
{
cfg.CreateMap<originClass, destClass>()
.ForMember(dest => dest.FieldA, opt => opt.Ignore())
.ForMember(dest => dest.FieldB, opt => opt.Ignore());
});
//步骤2. 创建自定义Mapper
var customMapper = customMapConfig.CreateMapper();
//步骤3. 执行
customMapper.Map<originClass, destClass>(objOrigin, objDest);
英文:
I had the same issue (IMappingOperationOptions not contain a definition for ConfigureMap) and I solved with a different approach.
//Step 1. Create a MapperConfiguration
var customMapConfig = new MapperConfiguration(cfg => {
cfg.CreateMap<originClass, destClass>()
.ForMember(dest => dest.FieldA, opt => opt.Ignore())
.ForMember(dest => dest.FieldB, opt => opt.Ignore());
});
//Step 2. Create the custom Mapper
var customMapper = customMapConfig.CreateMapper();
//Step 3. Execute
customMapper.Map<originClass, destClass>(objOrigin, objDest);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论