0
votes

I have dto object:

public class SwivelInfoToViewDTO { public ResponseValue Value { get; set; }

    public List<ResponseDocument> Documents { get; set; }

    public string Status { get; set; }
}

public class ResponseValue
{
    public string SerialNumber { get; set; }

    public string ProductCode { get; set; }

    public string ProductName { get; set; }
}

public class ResponseDocument
{
    public string Language { get; set; }

    public int DocumentTypeId { get; set; }

    public string DocumentType { get; set; }

}

And i have my sorce class:

            public class SwivelInformationResponse
            {
                public ResponseValue Value { get; set; }

                public string Status { get; set; }
            }

            public class ResponseValue
            {
                [JsonProperty("serial_number")]
                public string SerialNumber { get; set; }

                [JsonProperty("product_code")]
                public string ProductCode { get; set; }

                public List<ResponseDocument> Documents { get; set; }
            }

            public class ResponseDocument
            {
                [JsonProperty("language")]
                public string Language { get; set; }

                [JsonProperty("document_type_id")]
                public int DocumentTypeId { get; set; }

                [JsonProperty("document_type")]
                public string DocumentType { get; set; }

            }

I use auto-mapper and my profile looks like this:

        public MappingProfile()
        {
            CreateMap<SwivelInformationResponse, SwivelInfoToViewDTO>()
                .ForMember(x => x.Value, s => s.MapFrom(src => src.Value))
                .ForMember(x => x.Documents, s => s.MapFrom(src => src.Value.Documents));
        }

But somehow I get an error: Error mapping types. Destination Member: Value

How do I make bindings correctly?

1

1 Answers

3
votes

You forgot to map your ResponseValue and ResponseDocument classes. It's not the same classes so you need to map them as well.

public MappingProfile()
{
    CreateMap<SourceNamespace.ResponseValue, DtoNamespace.ResponseValue>();
    CreateMap<SourceNamespace.ResponseDocument, DtoNamespace.ResponseDocument>();
}