AutoMapper Problem - List won't Map
Posted
by Randy Minder
on Stack Overflow
See other posts from Stack Overflow
or by Randy Minder
Published on 2010-03-15T01:02:33Z
Indexed on
2010/03/15
1:09 UTC
Read the original article
Hit count: 673
automapper
I have the following class:
public class Account
{
public int AccountID { get; set; }
public Enterprise Enterprise { get; set; }
public List<User> UserList { get; set; }
}
And I have the following method fragment:
Entities.Account accountDto = new Entities.Account();
DAL.Entities.Account account;
Mapper.CreateMap<DAL.Entities.Account, Entities.Account>();
Mapper.CreateMap<DAL.Entities.User, Entities.User>();
account = DAL.Account.GetByPrimaryKey(this.Database, primaryKey, withChildren);
Mapper.Map(account,accountDto);
return accountDto;
When the method is called, the Account class gets mapped correctly but the list of users in the Account class does not (it is NULL). There are four User entities in the List that should get mapped. Could someone tell me what might be wrong?
© Stack Overflow or respective owner