Open orchardbot opened 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();
}
@bleroy created: https://orchard.codeplex.com/workitem/17271
Otherwise you must either do wasteful queries or go through repositories directly.