【发布时间】:2011-10-28 16:09:05
【问题描述】:
我有多个类需要映射为 1 个类:
这是我映射的来源(视图模型):
public class UserBM
{
public int UserId { get; set; }
public string Address { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string State { get; set; }
public int CountryId { get; set; }
public string Country { get; set; }
}
目标类是这样的(领域模型):
public abstract class User
{
public int UserId { get; set; }
public virtual Location Location { get; set; }
public virtual int? LocationId { get; set; }
}
public class Location
{
public int LocationId { get; set; }
public string Address { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string State { get; set; }
public virtual int CountryId { get; set; }
public virtual Country Country { get; set; }
}
这是我的自动映射器创建地图当前的样子:
Mapper.CreateMap<UserBM, User>();
根据 automapper codeplex 网站上的文档,这应该是自动的,但它不起作用。 Address、Address2 等仍然为空。我的 createmap 应该是什么样的?
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 automapper