Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automapper Custom configuration for members is only supported for top-level individual members on a type

I am trying to map a result I get from database and I have the following models

public class ClientTest
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public class ClientTestDto
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public class ClientDbItem
{
    public ClientTest Client { get; set; }
    public Address Address { get; set; }
}

public class Address
{
    public int Id { get; set; }
    public string Value { get; set; }
}

and the following mapping

CreateMap<ClientTest, ClientTestDto>();

CreateMap<ClientDbItem, ClientTestDto>()
    .ForMember(dest => dest, opt => opt.MapFrom(src => src.Client));

When I run the software I get

Custom configuration for members is only supported for top-level individual members on a type

Why is that happening If I am creating the config for ClientTest and ClientTestDto first?

like image 249
pantonis Avatar asked Dec 18 '19 09:12

pantonis


1 Answers

There's a special API for that, IncludeMembers. See here.

like image 125
Lucian Bargaoanu Avatar answered Sep 20 '22 02:09

Lucian Bargaoanu