使用ForSourceMember时AutoMapper的Ignore()无法正常工作吗? [英] AutoMapper's Ignore() not working when using ForSourceMember?
本文介绍了使用ForSourceMember时AutoMapper的Ignore()无法正常工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试忽略源类型的属性.我已经定义了这样的映射:
I'm trying to ignore a property from source type. I have defined mapping like this:
var map = AutoMapper.Mapper.CreateMap<Article, IArticle>();
map.ForSourceMember(s => s.DateCreated, opt => opt.Ignore());
map.ForSourceMember(s => s.DateUpdated, opt => opt.Ignore());
当我调用Map函数时,
When I call Map function,
AutoMapper.Mapper.Map(article, articlePoco);
目的地的属性仍然会更新.我正在使用从NuGet下载的最新稳定版本.
destination's properties gets updated anyway. I'm using the latest stable version downloaded from NuGet.
有什么想法为什么不起作用?
Any ideas why this isn't working ?
我找到了与此类似的问题,但没有附加答案. [问题]: AutoMapper的Ignore()无法正常工作吗?
I have found similar question to this one but there is no answer attached. [question]:AutoMapper's Ignore() not working?
推荐答案
更改映射以使用ForMember:
Change the mapping to use ForMember:
map.ForMember(s => s.DateCreated, opt => opt.Ignore());
map.ForMember(s => s.DateUpdated, opt => opt.Ignore());
这篇关于使用ForSourceMember时AutoMapper的Ignore()无法正常工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文