简体   繁体   English

使用 C# 自动映射器映射引用表

[英]Mapping referenced table with C# automapper

Suppose I have a table Scopes which contains a foreign key to another table ( subscopes ) and I want to map it.假设我有一个表Scopes ,它包含另一个表( subscopes )的外键,我想映射它。 All columns available in my Scopes table as well as some columns from my referenced table ( subscopes ) are required to be mapped to a DTO.我的Scopes表中可用的所有列以及引用表( subscopes )中的一些列都需要映射到 DTO。

My questions are:我的问题是:

  1. What should be the content of DTO? DTO的内容应该是什么?
  2. How should I map using c# and Automapper?我应该如何使用 c# 和 Automapper 进行映射?
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));

Problem Solved.问题解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM