Automapper failing to map on IEnumerable

后端 未结 2 1422
情歌与酒
情歌与酒 2021-02-02 05:31

I have two classes like so:

public class SentEmailAttachment : ISentEmailAttachment
{
    public SentEmailAttachment();

    public string FileName { get; set; }         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-02-02 06:33

    EDIT: I found an easy way to use DynamicMap with collections.

    IEnumerable unmappedItems = Repository.GetItems();
    IEnumerable mappedItems = unmappedItems.Select(Mapper.DynamicMap);
    

    — Original message —

    The way Jimmy says to use it works, but I try to use DynamicMap when I can to avoid having to do "CreateMap" for every mapping I need. I don't think DynamicMap works with collections very well, if at all. It does not throw an exception, but the result is an empty set.

    From testing over the past couple of days, you cannot use DynamicMap for collections at this time (that I know of).

提交回复
热议问题