Mapping collections using AutoMapper

后端 未结 2 833
感情败类
感情败类 2020-12-25 11:38

I\'m trying to map an array into an ICollection of type .

Basically I want to be able to do:

Mapper.CreateMap

        
相关标签:
2条回答
  • 2020-12-25 12:00

    Now it looks like you can use:

    Mapper.CreateMap<X,Y>(); 
    var listOfX = Mapper.Map<List<X>>(someIEnumerableOfY);
    
    0 讨论(0)
  • 2020-12-25 12:05

    You don't need to setup your mapping for collections, just the element types. So just:

    Mapper.CreateMap<X, Y>();
    Mapper.Map<X[], Collection<Y>>(objectToMap);
    

    See here for more info: http://automapper.codeplex.com/wikipage?title=Lists%20and%20Arrays&referringTitle=Home

    0 讨论(0)
提交回复
热议问题