c# - LINQ Group by for keyvaluepair data -


hello using linq in asp.net mvc application questions per ids inserted in answer table.

i have table data this:

enter image description here

here in above picture can see scheduleid there in 2 tables first table used assign question scheduleid's , second table storing answer of questions scheduleid.

now have take questions of scheduled question table , answer of question's answer how many star customer has given. 5 star , 4 star, 3 star etc... etc...

so in second table have given example questionid 1 there 4 answers given scheduleid 7543.

i want take data such way questions list count of given answer questionid 1 have 4 answers

q1 5(2 times) q1 2(1 time) q1 2(3 time)

like have created 1 class:

public class question     {         public int questionid { get; set; }         public string questiontext { get; set; }         public list<keyvaluepair<string,string>> answerlist { get; set; }     } 

so per above class

i have written query:

list<question> questionlist = (from queans in context.get<guestratinganswers>()                                            join regque in context.get<guestrankingquestions>()                                             on queans.questionid equals regque.id                                            orderby queans.questionid, queans.addedon descending                                            group new { queans, regque } new                                            {                                                queans.questionid,                                                regque.question,                                                regque.addedon                                            }                                g                                            select new question                                            {                                                questionid = g.key.questionid,                                                questiontext = g.key.question                                                //answerlist = new list<keyvaluepair<string, string>>()                                            }).orderby(n => n.questionid).tolist();              foreach (var item in questionlist)             {                  var detail = (from queans in context.get<guestratinganswers>()                 .groupby(n => n.answer).                      select(grp => new keyvaluepair<string, string>(grp.key.tostring(), grp.count().tostring()))).tolist();                  var details = (from queans in context.get<guestratinganswers>()                                orderby queans.answer descending                                group new { queans } new                                {                                    queans.answer                                }                                 g                                select new keyvaluepair<string, string>(g.key.answer.tostring(), g.key.answer.tostring()));             } 

in above query in each want answer count of answer keyvaluepair incomplete complete or there mistake have done please mention.

query used var detail , details both different given test.

thanks in advance. :)


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -