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

4
  • It could be helpful for you stackoverflow.com/questions/5589471/… Commented Nov 23, 2018 at 4:42
  • doesn't help me i think, i will edit to show diff Commented Nov 23, 2018 at 4:54
  • The full error message should tell you what the problem is. Commented Nov 23, 2018 at 6:54
  • there is no error message, it simply doesnt map the NavigationEntity Commented Nov 23, 2018 at 21:50

1 Answer 1

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 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.