0

I'm trying to create map for automapper to let me map those entity

Entities

public class Entity 
{
    ...
    public List<NavigationEntity> Navs { get; set; }
}

public class NavigationEntity   
{
    public int Id { get; set; }
}

DTO that need to be create with entities

public class EntityDto 
{
    ...
    public List<int> NavIds { get; set; }
}

This doesnt seem's to do the job! What could do the job ?

CreateMap<Entity, EntityDto>().ReverseMap();
CreateMap<NavigationEntity, int>().ConstructUsing(x => x.Id);

EDIT

Tried to add
CreateMap< List < SystemsTags >, List< int >>();

but still it doesnt map

Vince
  • 1,279
  • 2
  • 20
  • 40

1 Answers1

0

First of all, you should rename public List<NavigationEntity> Navs { get; set; } and public List<int> NavIds { get; set; } to the same name. If it is still not working try to also change ConstructUsing to ConvertUsing. And if you need the reverseMap of Entity to EntityDTO you should also add

CreateMap<int, NavigationEntity>().ConvertUsing(x => new NavigationEntity { Id = x });

final code

public class Entity 
{
    ...
    public List<NavigationEntity> Navs { get; set; }
}

public class NavigationEntity   
{
    public int Id { get; set; }
}

public class EntityDto 
{
    ...
    public List<int> Navs { get; set; }
}

...
CreateMap<Entity, EntityDto>().ReverseMap();
CreateMap<NavigationEntity, int>().ConvertUsing(x => x.Id);
CreateMap<int, NavigationEntity>().ConvertUsing(x => new NavigationEntity { Id = x });
Dimitris Maragkos
  • 8,932
  • 2
  • 8
  • 26