Mapping Virtual Property Automapper

automapper-5 c# entity-framework-6

Question

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);
1
0
7/17/2016 11:24:26 PM

Accepted Answer

Try this for your MapperConfiguration:

var config = new MapperConfiguration(cfg =>
{
    cfg.CreateMap<Group, GroupInfo>();
    cfg.CreateMap<User, UserInfo>();
});
1
7/17/2016 8:56:05 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow