假设我有一个表Scopes
,其中包含另一个表(subscopes
)的外键,我想映射它。我的Scopes
表中可用的所有列以及我引用的表中的一些列(subscopes
)都需要映射到DTO。
我的问题是:
答案 0 :(得分:0)
this.CreateMap<tblSubScope, Sub2MainScopeDto>()
.ForMember(t => t.IdxSubScope, opt => opt.MapFrom(s => s.idxSubScope))
.ForMember(t => t.IdxMainScope, opt => opt.MapFrom(s => s.idxMainScope))
.ForMember(t => t.SubScopeDescription, opt => opt.MapFrom(s => s.strSubScope))
.ForMember(t => t.MainScopeDescription, opt => opt.MapFrom(s => s.tblMainScope.strMainScope))
.ReverseMap()
.ForMember(t => t.idxSubScope, opt => opt.MapFrom(s => s.IdxSubScope))
.ForMember(t => t.strSubScope, opt => opt.MapFrom(s => s.SubScopeDescription))
.ForMember(t => t.idxMainScope, opt => opt.MapFrom(s => s.IdxMainScope));
解决了问题。