I have an issue with auto mapper which throws a Null reference exception.
Mapper.CreateMap<People, PeopleDto>()
      .ForMember(d => d.Country, opt => opt.MapFrom(o => o.Address.Country)) 
The problem is when Address is null and trying to get map Address.Country
Mapper.CreateMap() 
    .ForMember(d => d.Country, 
        opt => opt.MapFrom(
            o => (o.Address != null) ? o.Address.Country : "ADDRESS NOT SPECIFIED"
        )
    )
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With