asp.net mvc 4 - How to count duplicated items -


  ourproblems = db.problems.groupby(m => m.title).select(g => g.firstordefault())             .select(s => new  problemsmodel.problems             {                 id = s.id,                 name=s.name,                 text=s.text,              }) 

so here duplicated items need number 1 if there 5 duplicated items gives me name. want give me 5 items have

edit working;

 ourproblems = db.problems.groupby(m => m.title)             .select(s => new  problemsmodel.problems             {                 id = s.firstordefault().id,                 name = s.firstordefault().name,                 text=s.firstordefault().text,                 countitem=s.count(),                }) 

you need eliminate first select , move first behavior inside second select. try this:

list<probleminstance> ourproblems =  db.problems     .groupby(m => m.title)     .select(s => new probleminstance         {             id = s.first().id,             name = s.first().name,             text = s.first().text,             numberofoccurences = s.count(),         }).tolist(); 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -