【发布时间】:2014-05-22 20:02:04
【问题描述】:
我有一个场景,我必须做以下映射
public class Company : BaseEntity
{
public string Name { get; set; }
public virtual ICollection<CompanyService> CompanyServices { get; set; }
}
public class Service : BaseEntity
{
public string Name { get; set; }
public virtual ICollection<CompanyService> CompanyServices { get; set; }
}
public class CompanyService : BaseEntity
{
public long CompanyID { get; set; }
public virtual Company Company { get; set; }
public long ServiceID { get; set; }
public virtual Service Service { get; set; }
}
以及对应的视图模型
public class CompanyViewModel : BaseEntity
{
public string Name { get; set; }
public string Services { get; set; }
}
public class ServiceViewModel : BaseEntity
{
public string Name { get; set; }
}
public class CompanyServiceViewModel : BaseEntity
{
public string ServiceName { get; set; }
}
我想使用 AutoMapper 进行映射,其中我应该在 CompanyViewModel 类中以逗号分隔的字符串形式获取服务名称
Mapper.CreateMap<Company, CompanyViewModel>();
【问题讨论】:
标签: automapper