2017-07-07 847 views
0

,我发现了以下错误Automapper:Automapper 6.1.1异常使用MemberList.Source:未映射成员被发现

Unmapped members were found. Review the types and members below. 
Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type 
For no matching constructor, add a no-arg ctor, add optional arguments, or map all of the constructor parameters 

配置是这样的:

cfg.CreateMap<ArticleViewModel, Article>(MemberList.Source) 
    .EqualityComparison((src, dst) => src.Id == dst.Id); 

通常我会解决它就像.ForMember(x => x.NoMapProp, opt => opt.Ignore())但由于我使用MemberList.Source我无法使用ForMember访问该媒体资源。我该如何解决这个问题?

回答

0

这是很容易,解决这样的:

cfg.CreateMap<ArticleViewModel, Article>(MemberList.Source) 
    .EqualityComparison((src, dst) => src.Id == dst.Id) 
    .ForSourceMember(x => x.NoMapProp, opt => opt.Ignore());