OrchardCMS / Orchard

Orchard is a free, open source, community-focused Content Management System built on the ASP.NET MVC platform.
https://orchardproject.net
BSD 3-Clause "New" or "Revised" License
2.37k stars 1.12k forks source link

Add group by capabilities to ContentManager #1102

Open orchardbot opened 13 years ago

orchardbot commented 13 years ago

@bleroy created: https://orchard.codeplex.com/workitem/17271

Otherwise you must either do wasteful queries or go through repositories directly.

orchardbot commented 13 years ago

@bleroy commented:

Examples:

                              if (string.IsNullOrWhiteSpace(slug)) {
                                  tagCounts = (from tc in _contentTagRepository.Table
                                               where tc.TagsPartRecord.ContentItemRecord.Versions.Where(v => v.Published).Any()
                                               group tc by tc.TagRecord.TagName
                                                   into g
                                                   select new TagCount {
                                                       TagName = g.Key,
                                                       Count = g.Count()
                                                   }).ToList();
                              }
                              else {
                                  var container = _contentManager
                                      .Query<RoutePart, RoutePartRecord>()
                                      .ForVersion(VersionOptions.Published)
                                      .Where(c => c.Slug == slug)
                                      .List()
                                      .FirstOrDefault();
                                  if (container == default(RoutePart)) return new List<TagCount>();
                                  tagCounts = _contentManager
                                      .Query<TagsPart, TagsPartRecord>(VersionOptions.Published)
                                      .Join<CommonPartRecord>()
                                      .Where(t => t.Container.Id == container.Id)
                                      .List()
                                      .SelectMany(t => t.CurrentTags)
                                      .GroupBy(t => t.TagName)
                                      .Select(g => new TagCount {
                                          TagName = g.Key,
                                          Count = g.Count()
                                      })
                                      .ToList();
                              }