Below JSON
is the output from a stored procedure. I would like to generate a class which divides into group of classes based on question type questions and it has answers as a list to each question.
My class hierarchy :
public class QuestionarieDisplay
{
public QuestionarieDisplay()
{
QuestionTypeList = new List<QuestionTypeList>();
}
public Nullable<int> QuestionnaireId { get; set; }
public Nullable<int> QuestionnaireGroupId { get; set; }
public string QuestionnaireGroup { get; set; }
public List<QuestionTypeList> QuestionTypeList { get; set; }
}
public class QuestionTypeList
{
public QuestionTypeList()
{
QuestionList= new List<QuestionList>();
}
public Nullable<int> QuestionTypeId { get; set; }
public string QuestionType { get; set; }
public List<QuestionList> QuestionList{ get; set; }
}
public class QuestionList
{
public QuestionList()
{
Answer= new List<Answer>();
}
public List<Answer> Answer { get; set; }
public Nullable<int> QuestionId { get; set; }
public string Question { get; set; }
public Nullable<int> ScaleId { get; set; }
public string ScaleType { get; set; }
public string Attribute { get; set; }
public string AttributeValue { get; set; }
}
public class Answer
{
public string Answers { get; set; }
}
JSON Result from stored procedure:
{
"QuestionnaireId": 2,
"QuestionnaireGroupId": 1,
"QuestionnaireGroup": "Please rank based on the following areas",
"QuestionId": 2,
"Question": "Full Name?",
"QuestionTypeId": 3,
"QuestionType": "Short Text",
"ScaleId": null,
"ScaleType": null,
"Answers": null,
"Attribute": "Required",
"AttributeValue": "Yes"
},
{
"QuestionnaireId": 2,
"QuestionnaireGroupId": 1,
"QuestionnaireGroup": "Please rank based on the following areas",
"QuestionId": 5,
"Question": "Experience?",
"QuestionTypeId": 9,
"QuestionType": "Dropdown",
"ScaleId": null,
"ScaleType": null,
"Answers": null,
"Attribute": null,
"AttributeValue": null
},
{
"QuestionnaireId": 2,
"QuestionnaireGroupId": 1,
"QuestionnaireGroup": "Please rank based on the following areas",
"QuestionId": 7,
"Question": "Email Adddress?",
"QuestionTypeId": 3,
"QuestionType": "Short Text",
"ScaleId": null,
"ScaleType": null,
"Answers": null,
"Attribute": null,
"AttributeValue": null
},
{
"QuestionnaireId": 2,
"QuestionnaireGroupId": 1,
"QuestionnaireGroup": "Please rank based on the following areas",
"QuestionId": 12,
"Question": "Your comments?",
"QuestionTypeId": 4,
"QuestionType": "Long Text",
"ScaleId": null,
"ScaleType": null,
"Answers": null,
"Attribute": null,
"AttributeValue": null
},
I have divided it by:
var result = result.GroupBy(u => u.QuestionTypeId).Select(grp =>
grp.ToList()).ToList();
but I am not able to add it to list.
I would like to map result in the above class hierarchy.