如何使用AutoMapper .ForMember? [英] How to use AutoMapper .ForMember?

查看:4242
本文介绍了如何使用AutoMapper .ForMember?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立AutoMapper转换,从实体到DTO。我知道我应该使用 .ForMember() Mapper.CreateMap<实体,DTO>()建立自定义映射,但这似乎不是一个有效的方法。

I am trying to set up AutoMapper to convert from Entity to DTO. I know I'm supposed to be using .ForMember() after Mapper.CreateMap<Entity, DTO>() to set up custom mappings, but this doesn't seem to be an available method.

编辑澄清: 我不是在寻找一个链接的文档,我曾经读过的,或者基本语法的解释。我使用的是正确的语法中的答案和文档描述,例如:

Edit for clarification: I am not looking for a link to the documentation, which I have read, or an explanation of the basic syntax. I am using the correct syntax as described in answers and the documentation, for example:

Mapper.CreateMap<EFAddress, Address>().ForMember(dest => dest.Code, opt => opt.MapFrom(src => src.Name));

如果我有内CreateMap℃的无效的类型名称;>我可以看到ForMember作为一种有效的方法,鼠标悬停显示,因为我通常会想到的方法签名。但只要我给它两个有效的类型,ForMember说,它无法解析符号,因为如果该方法不可用。

If I have an invalid type name within CreateMap<> I can see "ForMember" as a valid method, mousing over shows the method signature as I would normally expect. But as soon as I give it two valid types, ForMember says it cannot resolve the symbol, as if the method is not available.

是否有某种约束的泛型类而我没有达到?

Is there some kind of constraint on the generic classes which I am not meeting?

感谢

推荐答案

在最后,我相信这竟然是一些不兼容的情况与ReSharper的。

In the end, I believe this turned out to be some kind of incompatibility with ReSharper.

ReSharper的似乎造成Automapper code显示不正常,但只是正常工作(即使它显示红色的错误消息)。卸载ReSharper的完全修复了这个问题。

ReSharper seems to have caused Automapper code to display incorrectly, but work just fine (even though it displays red with error messages). Uninstalling ReSharper fixed this issue completely.

这篇关于如何使用AutoMapper .ForMember?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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