繁体   English   中英

映射来自多个表的数据

[英]mapping data from more than one table

有什么办法可以使用Mapper.CreateMap()映射两个表中的数据? 例如:-我有两个表document和documentdetails。我想从两个表中获取数据并将它们映射到一个模型中,即documentmodel。如何在.net中使用上述方法来做到这一点? thanx :)

也许您可以在Automapper的ResolveUsing()中使用解析器。 例如:

    Mapper.CreateMap()
     .ForMember(x=>x.DocumentDetails, opt=>opt.ResolveUsing<DocumentDetailsResolver>()
        .FromMember(src=>src.Document.DocumentId);

然后在您的DocumentDetailsResolver类中:

    public class DocumentDetailsResolver: ValueResolver<int, List<DocumentDetails>{
       protected override List<DocumentDetails> ResolveCore(int source)
       {
          // Put your logic to get the list of document details, source is the ID of the document
         // Return the list
       }
    }

暂无
暂无

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

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