c# - linq with groupby and count -


It's very easy, but I'm hurt: looking at this type of data set:

  UserInfo (name, metric, day, other_metric)   

and this sample data set:

  joe 1 01/01/2011 5 jane 0 01/02/2011 9 John 2 01/03/2011 0 Jim 3 01/04/2011 1 Gen 1 01/05/2011 3 Jail 2 01/06/2011 5 Pock 0 01/07/2011 3 Jen 0 01 / 08/2011 7   

I would like to retrieve the table that sorts the metric (0,1,2,3 .. ..) counted with the total number of is. So you can end this set:

  0 3 1 2 2 2 3 1   

I'm battling the LINQ syntax but where is anyone The group was kept and counted .... any help ??

EDIT: I was never able to answer the answers posted because they always have a record with the number of different calculations. Although I could put SQL instance together from a LINQ that used to work: according to the information from

  var pl = R. r.metric group r by r.metric in grp new {key = Grp.Key, cnt = grp.Count ()};   

This result gave me an ordered set of records with the 'metric' and the number of users connected to each of them, I'm obviously new to LINQ and in my unreviewed eyes The approach looks similar to the pure LINQ approach, yet has given me a different answer. After calling


This was a brilliantly quick answer, but a problem with me is going to be a little bit the first line, especially "Data.groupby (info => info.metric)"

I think you already have a list / array of some class that Looks like

  class UserInfo {string name} int metric; ..etc ..} ... list & lt; UserInfo & gt; Data = .....;   data When groupb (x = & gt; x.metric) , it means " x  for each element defined in Iyumerable  data , this < Code> .metric , then group all the elements together with the same metric in  grouping  and return a  IEnumerable  of your resulting groups Data Set  
   | group key (x = & gt; x.metric) | 1 01/01/2011 5 1 Jen 0 01/02/2011 90 Zone 2 01/03/2011 0 2 Jim 3 01/04/2011 1 3 Gen 1 01/05/2011 3 1 Jill 2 01/06/2011 5 2 Pockets 01/07/2011 This will result in the following results from the group:  
  (group 1): [joe 01 01/03 / June 01 01/08/2011 7 0   

01/2011 5, Gene 1 01/05/2011 3] (Group 0): [Jen 01/02/2011 9, pocket 0 01/07/2011 3, Jane 01/08/2011 7] (Group 2 ): [John 2 01 / 03/2011 0, Jill 2 01/06/2011 5] (Group 3): [Jim 3 01/04/2011 1]

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -