Map to a collection property that is at different level than the one in source

54 views
Skip to first unread message

Neil Shah

unread,
Feb 7, 2021, 10:17:19 PM2/7/21
to AutoMapper-users
Hello Members,
I am very new to automapper and need your help in order to find the solution. I have a list of properties which is at a different level in the source and I want to map it to a list that is at different level of destination.

Please see the example below.

Source:
Class ExamObject{
public long id { get; set; }
public virtual Question Question { get; set; }
}

Class Question{
public long id { get; set; }  
public virtual ICollection<QuestionLanguage> QuestionLanguage { get; set; }
 public virtual ICollection<QuestionOption> QuestionOption { get; set; }
}

Class QuestionLanguage
{
public long id {get;set;}
public string text {get;set;}}
}

Class QuestionOption 
{
public long id {get;set;}
public virtual ICollection<QuestionOptionLanguage> QuestionOptionLanguage { get; set; }
}

Class QuestionOptionLanguage
{
public long id {get;set;} 
publice text {get;set} 
}

Destination Object:

Class Questiondto{
public long id {get;set;}  
public string QuestionText {get;set;}   
public List<Answer> Answers { get; set; }
}

class answer{
public long id {get;set;} 
publice answertext {get;set} 
}

I want to map examobject to Questiondto in such a way that
1. "ICollection<QuestionOptionLanguage> QuestionOptionLanguage" map to "List<Answer> Answers"
2. QuestionLanguage[0].Text to Questiondto.QuestionText

if someone can help me out then it will be appreciated.



Reply all
Reply to author
Forward
0 new messages