asp.net-mvc – Automapper映射到嵌套类
发布时间:2020-05-24 06:10:03 所属栏目:asp.Net 来源:互联网
导读:我有一个类,我需要t映射到多个类,例如. 这是我从(查看模型)映射的源: public class UserBM{ public int UserId { get; set; } public string Address { get; set; } public string Address2 { get; set; } public string Addre
|
我有一个类,我需要t映射到多个类,例如. 这是我从(查看模型)映射的源: 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; }
}
这是我的automapper创建地图当前的样子: Mapper.CreateMap<UserBM,User>(); 解决方法定义两个映射,从同一个源映射到不同的目的地.在用户映射中,使用Mapper.Map< UserBM,Location>(…)手动映射Location属性Mapper.CreateMap<UserBM,Location>();
Mapper.CreateMap<UserBM,User>()
.ForMember(dest => dest.Location,opt =>
opt.MapFrom(src => Mapper.Map<UserBM,Location>(src)); (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 防止在文本框中键入非ascii字符
- asp.net-mvc-4 – 如何在服务器上安装ASP.NET MVC4 RC(2008
- asp.net-mvc – 使用嵌套显示模板时如何防止Razor向输入添加
- 如何在ASP.NET生成的Word文件中嵌入图像
- 向ASP.NET Gridview添加动态列
- asp.net – 间歇性SQL连接错误
- asp.net – 如何为Umbraco创建项目包?
- asp.net-mvc – ASP.Net [HiddenInput]数据属性在Razor中用
- asp.net-mvc – ASP.NET MVC Route,在控制器之前具有值,没有
- ASP.NET性能优化之局部缓存分析
推荐文章
站长推荐
- asp.net-mvc – 为什么在ASP.NET MVC中使用lambd
- asp.net – 如何加密web.config中的一个条目
- asp.net-mvc – 如何在控制器中显示警报消息
- asp.net-mvc-4 – MVC4如何挂钩OnSessionStart事
- asp.net – 在Web.config更改后程序集不可用
- asp.net-mvc – 在MVC中结合JS / CSS的任何经验?
- asp.net-mvc和webforms共存
- asp.net – Microsoft JScript运行时错误:’Sys
- asp-classic – 如何在VBScript中逐行读取CSV文件
- Godaddy ASP.NET会员数据库困境
热点阅读
