Skip to content

Instantly share code, notes, and snippets.

@ttamminen
Created July 19, 2016 18:09
Show Gist options
  • Save ttamminen/f4fe95303845a90b4ccb3ceca8b75a1f to your computer and use it in GitHub Desktop.
Save ttamminen/f4fe95303845a90b4ccb3ceca8b75a1f to your computer and use it in GitHub Desktop.
void Main()
{
var sampleData = new List<Foo>();
sampleData.Add(new Foo { DocumentId = 1, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 2, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 3, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 2, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 2, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 2, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 3, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 2, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 1, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 1, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 4, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 5, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 6, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 5, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 8, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 10, AccessGroupId = 1 });
sampleData.Add(new Foo { DocumentId = 2, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 2, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 2, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 3, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 3, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 3, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 3, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 3, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 3, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 3, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 3, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 4, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 4, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 4, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 4, AccessGroupId = 2 });
sampleData.Add(new Foo { DocumentId = 4, AccessGroupId = 2 });
var x = (from entry in sampleData
group entry by new { entry.DocumentId, entry.AccessGroupId } into g
orderby g.Key.AccessGroupId, g.Count() descending
select new { DocumentId = g.Key.DocumentId, AccessGroupId = g.Key.AccessGroupId, Count = g.Count() }
);
Console.WriteLine(x);
}
public class Foo {
public int DocumentId { get; set; }
public int AccessGroupId { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment