linq - IQueryable to get sum and order by descending in subset -
I have a collection of DTOs in which I want to make some order in the nested DTO with the sum of some values. / P>
This type of search is as follows:
One question is of QuestionDTO.
A question DTO has a lot of answers that have many votes.
In short:
1 question: question, question, question, answer: answer, answer, vote: vote, answer, value,
I have explained for each answer, and then for each question, order by this amount.
p> I think you want it: < Pre>
var question list = new list & lt; Question & gt; (); // Get a genuine list var sorted questions = (i select the list in question from i.QuestionID, i.QuestionText, VotesSum = i.Answers.Sum (ee = & gt; ee.Votes.Sum = & Gt; ss.Value))}) .OrderByDescending (ee => ee.VotesSum); Voroch (Miscellaneous items in the sorted quest) console Whiteline (item Q & A + + + + item quotes); Highlighting your classes are like
class vote {public int VoteID {get ; Set;} public int value {get} set;}} class response {public at answerID {get} set;} public string replytext {get; set;} public list & gt; vote & gt; vote = new list & lt ; Vote & gt; ();} class questions {public full query id {get; set;} public string query text {get; set;} Arwajnik List & lt; answer & gt; response = new List & lt; answer & gt; ();}
Comments
Post a Comment