簡體   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