group and add list of items of object C#
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
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.
c#
add a comment |
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.
c#
I think you need to add intermediate class: show thoses cases was use off deserialize json on c# stackoverflow.com/questions/7895105/…
– pascal sanchez
Jan 4 at 8:06
This codegrp => grp.ToList()
means if i'm not mistaken result = group of list. My question is in which part of yourclass hierarchy
do you want to store theresult
?
– Vijunav Vastivch
Jan 4 at 8:17
add a comment |
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.
c#
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.
c#
c#
edited Jan 4 at 8:22
derHugo
9,93331635
9,93331635
asked Jan 4 at 7:55
priya_21priya_21
61112
61112
I think you need to add intermediate class: show thoses cases was use off deserialize json on c# stackoverflow.com/questions/7895105/…
– pascal sanchez
Jan 4 at 8:06
This codegrp => grp.ToList()
means if i'm not mistaken result = group of list. My question is in which part of yourclass hierarchy
do you want to store theresult
?
– Vijunav Vastivch
Jan 4 at 8:17
add a comment |
I think you need to add intermediate class: show thoses cases was use off deserialize json on c# stackoverflow.com/questions/7895105/…
– pascal sanchez
Jan 4 at 8:06
This codegrp => grp.ToList()
means if i'm not mistaken result = group of list. My question is in which part of yourclass hierarchy
do you want to store theresult
?
– Vijunav Vastivch
Jan 4 at 8:17
I think you need to add intermediate class: show thoses cases was use off deserialize json on c# stackoverflow.com/questions/7895105/…
– pascal sanchez
Jan 4 at 8:06
I think you need to add intermediate class: show thoses cases was use off deserialize json on c# stackoverflow.com/questions/7895105/…
– pascal sanchez
Jan 4 at 8:06
This code
grp => grp.ToList()
means if i'm not mistaken result = group of list. My question is in which part of your class hierarchy
do you want to store the result
?– Vijunav Vastivch
Jan 4 at 8:17
This code
grp => grp.ToList()
means if i'm not mistaken result = group of list. My question is in which part of your class hierarchy
do you want to store the result
?– Vijunav Vastivch
Jan 4 at 8:17
add a comment |
2 Answers
2
active
oldest
votes
Assuming that you have something like
public class RawDataDTO
{
public Nullable<int> QuestionnaireId { get; set; }
public Nullable<int> QuestionnaireGroupId { get; set; }
public string QuestionnaireGroup { get; set; }
public Nullable<int> QuestionTypeId { get; set; }
public string QuestionType { get; set; }
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; }
}
you could use:
List<RawDataDTO> raw = // your data in raw format
List<QuestionarieDisplay> list = raw
.GroupBy(r => new { r.QuestionnaireGroup, r.QuestionnaireGroupId, r.QuestionnaireId })
.Select(r => new QuestionarieDisplay()
{
QuestionnaireId = r.Key.QuestionnaireId,
QuestionnaireGroupId = r.Key.QuestionnaireGroupId,
QuestionnaireGroup = r.Key.QuestionnaireGroup,
QuestionTypeList =
r.GroupBy(t => new { t.QuestionType, t.QuestionTypeId })
.Select(t => new QuestionTypeList
{
QuestionType = t.Key.QuestionType,
QuestionTypeId = t.Key.QuestionTypeId,
QuestionList = t.Select(x => new QuestionList
{
QuestionId = x.QuestionId
})
.ToList()
})
.ToList()
}).ToList();
appreciated thank you so much.
– priya_21
Feb 11 at 6:42
add a comment |
Right now your are declaring the classes QuestionTypeList and QuestionList as generic lists like in:
public List<QuestionList> QuestionList{ get; set; }
An option could be to change both classes to implement a list, using this approach, you are going to be able to override the list methods like 'add' and 'exists' putting inside all the logic you need to add a new item to the list.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54035029%2fgroup-and-add-list-of-items-of-object-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Assuming that you have something like
public class RawDataDTO
{
public Nullable<int> QuestionnaireId { get; set; }
public Nullable<int> QuestionnaireGroupId { get; set; }
public string QuestionnaireGroup { get; set; }
public Nullable<int> QuestionTypeId { get; set; }
public string QuestionType { get; set; }
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; }
}
you could use:
List<RawDataDTO> raw = // your data in raw format
List<QuestionarieDisplay> list = raw
.GroupBy(r => new { r.QuestionnaireGroup, r.QuestionnaireGroupId, r.QuestionnaireId })
.Select(r => new QuestionarieDisplay()
{
QuestionnaireId = r.Key.QuestionnaireId,
QuestionnaireGroupId = r.Key.QuestionnaireGroupId,
QuestionnaireGroup = r.Key.QuestionnaireGroup,
QuestionTypeList =
r.GroupBy(t => new { t.QuestionType, t.QuestionTypeId })
.Select(t => new QuestionTypeList
{
QuestionType = t.Key.QuestionType,
QuestionTypeId = t.Key.QuestionTypeId,
QuestionList = t.Select(x => new QuestionList
{
QuestionId = x.QuestionId
})
.ToList()
})
.ToList()
}).ToList();
appreciated thank you so much.
– priya_21
Feb 11 at 6:42
add a comment |
Assuming that you have something like
public class RawDataDTO
{
public Nullable<int> QuestionnaireId { get; set; }
public Nullable<int> QuestionnaireGroupId { get; set; }
public string QuestionnaireGroup { get; set; }
public Nullable<int> QuestionTypeId { get; set; }
public string QuestionType { get; set; }
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; }
}
you could use:
List<RawDataDTO> raw = // your data in raw format
List<QuestionarieDisplay> list = raw
.GroupBy(r => new { r.QuestionnaireGroup, r.QuestionnaireGroupId, r.QuestionnaireId })
.Select(r => new QuestionarieDisplay()
{
QuestionnaireId = r.Key.QuestionnaireId,
QuestionnaireGroupId = r.Key.QuestionnaireGroupId,
QuestionnaireGroup = r.Key.QuestionnaireGroup,
QuestionTypeList =
r.GroupBy(t => new { t.QuestionType, t.QuestionTypeId })
.Select(t => new QuestionTypeList
{
QuestionType = t.Key.QuestionType,
QuestionTypeId = t.Key.QuestionTypeId,
QuestionList = t.Select(x => new QuestionList
{
QuestionId = x.QuestionId
})
.ToList()
})
.ToList()
}).ToList();
appreciated thank you so much.
– priya_21
Feb 11 at 6:42
add a comment |
Assuming that you have something like
public class RawDataDTO
{
public Nullable<int> QuestionnaireId { get; set; }
public Nullable<int> QuestionnaireGroupId { get; set; }
public string QuestionnaireGroup { get; set; }
public Nullable<int> QuestionTypeId { get; set; }
public string QuestionType { get; set; }
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; }
}
you could use:
List<RawDataDTO> raw = // your data in raw format
List<QuestionarieDisplay> list = raw
.GroupBy(r => new { r.QuestionnaireGroup, r.QuestionnaireGroupId, r.QuestionnaireId })
.Select(r => new QuestionarieDisplay()
{
QuestionnaireId = r.Key.QuestionnaireId,
QuestionnaireGroupId = r.Key.QuestionnaireGroupId,
QuestionnaireGroup = r.Key.QuestionnaireGroup,
QuestionTypeList =
r.GroupBy(t => new { t.QuestionType, t.QuestionTypeId })
.Select(t => new QuestionTypeList
{
QuestionType = t.Key.QuestionType,
QuestionTypeId = t.Key.QuestionTypeId,
QuestionList = t.Select(x => new QuestionList
{
QuestionId = x.QuestionId
})
.ToList()
})
.ToList()
}).ToList();
Assuming that you have something like
public class RawDataDTO
{
public Nullable<int> QuestionnaireId { get; set; }
public Nullable<int> QuestionnaireGroupId { get; set; }
public string QuestionnaireGroup { get; set; }
public Nullable<int> QuestionTypeId { get; set; }
public string QuestionType { get; set; }
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; }
}
you could use:
List<RawDataDTO> raw = // your data in raw format
List<QuestionarieDisplay> list = raw
.GroupBy(r => new { r.QuestionnaireGroup, r.QuestionnaireGroupId, r.QuestionnaireId })
.Select(r => new QuestionarieDisplay()
{
QuestionnaireId = r.Key.QuestionnaireId,
QuestionnaireGroupId = r.Key.QuestionnaireGroupId,
QuestionnaireGroup = r.Key.QuestionnaireGroup,
QuestionTypeList =
r.GroupBy(t => new { t.QuestionType, t.QuestionTypeId })
.Select(t => new QuestionTypeList
{
QuestionType = t.Key.QuestionType,
QuestionTypeId = t.Key.QuestionTypeId,
QuestionList = t.Select(x => new QuestionList
{
QuestionId = x.QuestionId
})
.ToList()
})
.ToList()
}).ToList();
edited Jan 4 at 8:54
xdtTransform
598221
598221
answered Jan 4 at 8:29
Piotr WojsaPiotr Wojsa
657517
657517
appreciated thank you so much.
– priya_21
Feb 11 at 6:42
add a comment |
appreciated thank you so much.
– priya_21
Feb 11 at 6:42
appreciated thank you so much.
– priya_21
Feb 11 at 6:42
appreciated thank you so much.
– priya_21
Feb 11 at 6:42
add a comment |
Right now your are declaring the classes QuestionTypeList and QuestionList as generic lists like in:
public List<QuestionList> QuestionList{ get; set; }
An option could be to change both classes to implement a list, using this approach, you are going to be able to override the list methods like 'add' and 'exists' putting inside all the logic you need to add a new item to the list.
add a comment |
Right now your are declaring the classes QuestionTypeList and QuestionList as generic lists like in:
public List<QuestionList> QuestionList{ get; set; }
An option could be to change both classes to implement a list, using this approach, you are going to be able to override the list methods like 'add' and 'exists' putting inside all the logic you need to add a new item to the list.
add a comment |
Right now your are declaring the classes QuestionTypeList and QuestionList as generic lists like in:
public List<QuestionList> QuestionList{ get; set; }
An option could be to change both classes to implement a list, using this approach, you are going to be able to override the list methods like 'add' and 'exists' putting inside all the logic you need to add a new item to the list.
Right now your are declaring the classes QuestionTypeList and QuestionList as generic lists like in:
public List<QuestionList> QuestionList{ get; set; }
An option could be to change both classes to implement a list, using this approach, you are going to be able to override the list methods like 'add' and 'exists' putting inside all the logic you need to add a new item to the list.
answered Jan 4 at 8:25
Óscar AndreuÓscar Andreu
1,146728
1,146728
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54035029%2fgroup-and-add-list-of-items-of-object-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I think you need to add intermediate class: show thoses cases was use off deserialize json on c# stackoverflow.com/questions/7895105/…
– pascal sanchez
Jan 4 at 8:06
This code
grp => grp.ToList()
means if i'm not mistaken result = group of list. My question is in which part of yourclass hierarchy
do you want to store theresult
?– Vijunav Vastivch
Jan 4 at 8:17