An editor needed information about the number pages for each page type on their site.
The following simple code will retrieve all pages below the start page, group them by their page type name, and then count how many of each page type there is. It’s probably much, *much* faster to this via SQL, but I was feeling a bit lazy and did it this way instead:
var result = DataFactory.Instance.GetDescendents(PageReference.StartPage) .Select(DataFactory.Instance.GetPage) .OrderBy(page => page.PageTypeName) .GroupBy(page => page.PageTypeName) .Select(group => new { PageType = group.Key, Count = group.Count() }) .ToList();