diff --git a/Btms.Analytics/MovementsAggregationService.cs b/Btms.Analytics/MovementsAggregationService.cs index 7a4a9f8..ce31078 100644 --- a/Btms.Analytics/MovementsAggregationService.cs +++ b/Btms.Analytics/MovementsAggregationService.cs @@ -13,6 +13,7 @@ using MongoDB.Driver; using Btms.Analytics.Extensions; +using Microsoft.EntityFrameworkCore.Query.SqlExpressions; namespace Btms.Analytics; @@ -58,17 +59,11 @@ public Task ByItemCount(DateTime from, DateTime to) var mongoQuery = context .Movements .Where(n => n.CreatedSource >= from && n.CreatedSource < to) - .GroupBy(m => new { Linked = m.Relationships.Notifications.Data.Count > 0, Items = m.Items.Count }) - .GroupBy(g => g.Key.Linked); - + .GroupBy(m => new { Linked = m.Relationships.Notifications.Data.Count > 0, ItemCount = m.Items.Count }) + .Select(g => new { g.Key.Linked, g.Key.ItemCount, Count = g.Count() }); + var mongoResult = mongoQuery .Execute(logger) - .SelectMany(g => g.Select(l => new - { - Linked = g.Key, - ItemCount = l.Key.Items, - Count = l.Count() - })) .ToList(); var dictionary = mongoResult