开发者

mapping data from more than one table

is there any way to map data from two tables using Mapper.CreateMap()? eg:- i have two tables docu开发者_运维知识库ment and documentdetails.i want to get data from both tables and map them into one model which is documentmodel.how can i do this using the above method in .net? thanx:)


Perhaps you can use resolver in Automapper's ResolveUsing(). e.g:

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

Then in your DocumentDetailsResolver class:

    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
       }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜