fix: rewrite TopTags query to avoid EF Core collection navigation translation error
This commit is contained in:
@@ -62,11 +62,14 @@ public class StatsRepository(LactoseDbContext context) : IStatsRepository {
|
||||
dto.PublicAssets = context.Assets.Count(a => a.DeletedAt == null && a.IsPubliclyShared);
|
||||
dto.PrivateAssets = context.Assets.Count(a => a.DeletedAt == null && !a.IsPubliclyShared);
|
||||
|
||||
dto.TopTags = context.Tags
|
||||
.Select(t => new TagStatDto {
|
||||
Id = t.Id,
|
||||
Name = t.Name,
|
||||
AssetCount = t.Assets != null ? t.Assets.Count(a => a.DeletedAt == null) : 0
|
||||
dto.TopTags = context.Assets
|
||||
.Where(a => a.DeletedAt == null)
|
||||
.SelectMany(a => a.Tags)
|
||||
.GroupBy(t => new { t.Id, t.Name })
|
||||
.Select(g => new TagStatDto {
|
||||
Id = g.Key.Id,
|
||||
Name = g.Key.Name,
|
||||
AssetCount = g.Count()
|
||||
})
|
||||
.OrderByDescending(t => t.AssetCount)
|
||||
.Take(10)
|
||||
|
||||
Reference in New Issue
Block a user