문제

I am working in an ASP.NET MVC 4 application, and have something similar to this for my domain.

public class Party
{
    public Cake PartyCake { get; set; }
    public List<Candles> CakeCandles { get; set; }
}

I want to map that to the PartyVM which looks like so:

public class PartyVM
{
    public string PartyCakeName { get; set; }
    public int CandlesCount { get; set; }
}

How can I tell AutoMapper to work out the Count of the list when doing its mappings? I have this, but all this does is tell it to ignore!

Mapper.CreateMap<Party, PartyVM>()
            .ForMember(dest => dest.CandlesCount, opt => opt.Ignore());

Thanks.

도움이 되었습니까?

해결책

AutoMapper supports Count out of the box, your destination member is just named incorrectly. If you name your PartyVM property "CakeCandlesCount" it will have the right value.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top