简体   繁体   English

自动映射器从字典获取源值<string, string>

[英]Automapper get source value from a Dictionary<string, string>

I am trying to map from an item in a dictionary. 我正在尝试从词典中的项目进行映射。

class Dest
{
    Dictionary<string, string> dict { get; set; } = new Dictionary<string, string>();
}

class Src
{
    public string src { get; set }
}

mapper.CreateMap<Src, Dest>()
    .ForMember(m => m.src, opt.MapFrom(s => s.dict.SingleOrDefault(i => i.Key.Equals("id"))));

The item in the dictionary definitely exists but the value is not being mapped. 词典中的项目确实存在,但未映射值。

Any obvious mistakes? 有明显的错误吗?

Argh. 哎呀。 So it turns out my Dest class also has a property called src . 因此事实证明,我的Dest类还具有一个名为src的属性。 It seems mapper is doing my optional map and then also doing a default src to src map. 似乎mapper在做我的可选地图,然后还在做默认的srcsrc地图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM