Automapper 6.1.1使用MemberList.Source的异常:找到了未映射的成员

时间:2017-07-07 09:58:06

标签: c# automapper

我在Automapper中收到以下错误:

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访问该属性。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

很简单,就这样解决了:

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