2016-09-26 12 views
0

新しいオブジェクト内のリストオブジェクトにマップする必要があるプロパティの辞書を持つデータベースオブジェクトがあります。AutoMapperを使用して辞書の値をリストにマップする

public class DbObject { // The source 
    public Dictionary<string, DbCustomProperty> customProperties; 
} 

public class DbCustomProperty { 
    public string Key; 
    public string Value; 
} 



public class DTOObject { // The destination 
    public List<DTOCustomProperty> DTOCustomProperties; 
} 

public class DTOCustomProperty { 
    public string Key; 
    public string Value; 
} 

あなたが見ることができるように、私はDTOObject(宛先)にDBOBJECT(ソース)をマッピングしたいと思います:私の構造(簡素化)は次のようになります。問題は、私のDBObjectに、リストにマップしたいプロパティが値である辞書が含まれていることです。

例えば、 dBObject.CustomProperties.Values - > dtoObject.CustomProperties

これはAutoMapperで認識できますか?

+0

の可能性のある重複した[AutoMapper辞書フラット化](http://stackoverflow.com/questions/10519460/automapper-dictionary-flattening) –

答えて

0

あなたは使用することができます。

AutoMapper.CreateMap<IGrouping<string, DbCustomProperty>, DTOCustomProperty>() 
      .ForMember(dest => dest.Key, opt => opt.MapFrom(src => src.Key)) 
      .ForMember(dest => dest.Value, opt => opt.MapFrom(src => src.Value))); 
関連する問題