Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top