Created
July 19, 2016 18:09
-
-
Save ttamminen/f4fe95303845a90b4ccb3ceca8b75a1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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