问题描述
我有 3 个班级:
public class CountryModel
{
public int Id { get; set; }
public string Title { get; set; }
}
public class CountryDTO
{
public int Id { get; set; }
public string Title { get; set; }
}
public class BaseCountryDTO
{
public CountryDTO Country {get; set};
}
我需要将 CountryDTO 映射到 CountryModel,但通过 BaseCountryDTO 类。 我知道我可以这样做:
CreateMap<BaseCountryDTO,CountryModel>()
.ForMember(model => model.Id,o => o.MapFrom(dto => dto.Country.Id))
.ForMember(model => model.Title,o => o.MapFrom(dto => dto.Country.Title));
但我想说清楚,像这样:
// This is not working code,just my imagination :)
CreateMap<BaseCountryDTO,CountryModel>()
.ForMember(model => model,dto => dto.Country));
因为在模型中可以有 2 个以上的属性。有办法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)