From 01de3b480bf581b93319d72390fc0d68f37066e9 Mon Sep 17 00:00:00 2001 From: David Lebee Date: Sun, 21 Oct 2018 13:23:23 -0500 Subject: [PATCH] data is ready next is to regroup into a result :) --- PoweredSoft.DynamicQuery.Cli/Program.cs | 2 +- PoweredSoft.DynamicQuery/QueryHandler.cs | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/PoweredSoft.DynamicQuery.Cli/Program.cs b/PoweredSoft.DynamicQuery.Cli/Program.cs index 9addeee..0060abf 100644 --- a/PoweredSoft.DynamicQuery.Cli/Program.cs +++ b/PoweredSoft.DynamicQuery.Cli/Program.cs @@ -79,7 +79,7 @@ namespace PoweredSoft.DynamicQuery.Cli var queryable = list.AsQueryable(); var criteria = new QueryCriteria(); criteria.Page = 1; - criteria.PageSize = 10; + criteria.PageSize = 2; criteria.Groups = new List() { diff --git a/PoweredSoft.DynamicQuery/QueryHandler.cs b/PoweredSoft.DynamicQuery/QueryHandler.cs index c868cc3..16c0992 100644 --- a/PoweredSoft.DynamicQuery/QueryHandler.cs +++ b/PoweredSoft.DynamicQuery/QueryHandler.cs @@ -39,19 +39,16 @@ namespace PoweredSoft.DynamicQuery { var groupExpression = CurrentQueryable.GroupBy(QueryableUnderlyingType, gb => { - previousGroups.ForEach(pg => - { - var previousGroupCleanedPath = pg.Path.Replace(".", ""); - gb.Path(pg.Path, $"Key_{previousGroupCleanedPath}"); - }); - var cleanedPath = fg.Path.Replace(".", ""); - gb.Path(fg.Path, $"Key_{cleanedPath}"); + var groupKeyIndex = -1; + previousGroups.ForEach(pg =>gb.Path(pg.Path, $"Key_{++groupKeyIndex}")); + gb.Path(fg.Path, $"Key_{++groupKeyIndex}"); }); var selectExpression = groupExpression.Select(sb => { - previousGroups.ForEach(pg => sb.Key(pg.Path)); - sb.Key(fg.Path); + var groupKeyIndex = -1; + previousGroups.ForEach(pg => sb.Key($"Key_{++groupKeyIndex}")); + sb.Key($"Key_{++groupKeyIndex}"); Criteria.Aggregates.ForEach(a => { var selectType = ResolveSelectFrom(a.Type); @@ -80,10 +77,10 @@ namespace PoweredSoft.DynamicQuery ApplyPaging(); // now get the data grouped. - CurrentQueryable = CurrentQueryable.GroupBy(QueryableUnderlyingType, gb => finalGroups.ForEach(fg => gb.Path(fg.Path))); + CurrentQueryable = CurrentQueryable.GroupBy(QueryableUnderlyingType, gb => finalGroups.ForEach((fg, index) => gb.Path(fg.Path, $"Key_{index}"))); CurrentQueryable = CurrentQueryable.Select(sb => { - finalGroups.ForEach(fg => sb.Key(fg.Path)); + finalGroups.ForEach((fg, index) => sb.Key($"Key_{index}")); sb.ToList("Records"); });