0

I have some problem with mapping models . So I have a entity model

public class User
{
    public string UserId { get; set;}

    public ICollection<Group> Groups {get; set;}
}

and DTO model

public class UserInfo
{   
    public string UserId { get; set;}  

    public List<GroupInfo> Groups {get; set;}
}

So I have problem when mapping User to UserInfo Missing configuration type for GroupInfo . How intialize second mapping ?

User is mapped to UserInfo as the following:

var config = new MapperConfiguratiins(cfg=>cfg.CreateMap<User,UserInfo>()); 
var mapper = config.CreateMapper();
var userInfo = mapper.Map<UserInfo>(user);
Timothy Ghanem
  • 1,606
  • 11
  • 20
Alexandr Sargsyan
  • 656
  • 1
  • 6
  • 21

1 Answers1

1

Try this for your MapperConfiguration:

var config = new MapperConfiguration(cfg =>
{
    cfg.CreateMap<Group, GroupInfo>();
    cfg.CreateMap<User, UserInfo>();
});
Timothy Ghanem
  • 1,606
  • 11
  • 20
  • It works , but I forgot that in my Group there is User reference also it is many to many relation. So I ignore this member mapping. otherwise it causing StackOverflow exception. And it is normal. So it is exist some pretty method to workaround or opt.Ignore is best solution? – Alexandr Sargsyan Jul 17 '16 at 21:13
  • 1
    Yes, ignoring the user reference in the Group should be the solution to it. – Timothy Ghanem Jul 17 '16 at 21:16