pieces are ready to connect :P
This commit is contained in:
		
							parent
							
								
									8ca897b304
								
							
						
					
					
						commit
						244130c4cb
					
				@ -48,6 +48,7 @@ namespace PoweredSoft.DynamicQuery.Cli
 | 
			
		||||
        public string FirstName { get; set; }
 | 
			
		||||
        public string LastName { get; set; }
 | 
			
		||||
        public int Age { get; set; }
 | 
			
		||||
        public string Sexe { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class OtherClass
 | 
			
		||||
@ -68,11 +69,11 @@ namespace PoweredSoft.DynamicQuery.Cli
 | 
			
		||||
        {
 | 
			
		||||
            var list = new List<Person>()
 | 
			
		||||
            {
 | 
			
		||||
                new Person{ Id = 1, FirstName = "David", LastName = "Lebee", Age = 29},
 | 
			
		||||
                new Person{ Id = 2, FirstName = "Michaela", LastName = "Lebee", Age = 29},
 | 
			
		||||
                new Person{ Id = 3, FirstName = "Zohra", LastName = "Lebee", Age = 20},
 | 
			
		||||
                new Person{ Id = 4, FirstName = "Eric", LastName = "Vickar", Age = 30},
 | 
			
		||||
                new Person{ Id = 5, FirstName = "Susan", LastName = "Vickar", Age = 30},
 | 
			
		||||
                new Person{ Id = 1, FirstName = "David", LastName = "Lebee", Sexe = "Male", Age = 29},
 | 
			
		||||
                new Person{ Id = 2, FirstName = "Michaela", LastName = "Lebee", Sexe = "Female", Age = 29},
 | 
			
		||||
                new Person{ Id = 3, FirstName = "Zohra", LastName = "Lebee", Sexe = "Female", Age = 20},
 | 
			
		||||
                new Person{ Id = 4, FirstName = "Eric", LastName = "Vickar", Sexe = "Male", Age = 30},
 | 
			
		||||
                new Person{ Id = 5, FirstName = "Susan", LastName = "Vickar", Sexe = "Female", Age = 30},
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var queryable = list.AsQueryable();
 | 
			
		||||
@ -80,30 +81,15 @@ namespace PoweredSoft.DynamicQuery.Cli
 | 
			
		||||
            criteria.Page = 1;
 | 
			
		||||
            criteria.PageSize = 10;
 | 
			
		||||
 | 
			
		||||
            /*
 | 
			
		||||
            criteria.Filters = new List<IFilter>
 | 
			
		||||
            {
 | 
			
		||||
                new SimpleFilter() {Path = nameof(Person.LastName), Value = "Lebee", Type = FilterType.Equal},
 | 
			
		||||
                new CompositeFilter()
 | 
			
		||||
                {
 | 
			
		||||
                    Type = FilterType.Composite,
 | 
			
		||||
                    And = true,
 | 
			
		||||
                    Filters = new List<IFilter>
 | 
			
		||||
                    {
 | 
			
		||||
                        new SimpleFilter() {Path = nameof(Person.FirstName), Value = "David", Type = FilterType.Equal},
 | 
			
		||||
                        new SimpleFilter() {Path = nameof(Person.FirstName), Value = "Zohra", Type = FilterType.Equal},
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            };*/
 | 
			
		||||
 | 
			
		||||
            criteria.Groups = new List<IGroup>()
 | 
			
		||||
            {
 | 
			
		||||
                new Group { Path = "LastName" }
 | 
			
		||||
                new Group { Path = "LastName" },
 | 
			
		||||
                new Group { Path = "Sexe" }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            criteria.Aggregates = new List<IAggregate>()
 | 
			
		||||
            {
 | 
			
		||||
                new Aggregate { Path = "Age", Type = AggregateType.Count },
 | 
			
		||||
                new Aggregate { Type = AggregateType.Count },
 | 
			
		||||
                new Aggregate { Path = "Age", Type = AggregateType.Avg }
 | 
			
		||||
            };;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -4,6 +4,7 @@ using System.Linq;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using PoweredSoft.DynamicLinq;
 | 
			
		||||
using PoweredSoft.DynamicLinq.Fluent;
 | 
			
		||||
using PoweredSoft.DynamicQuery.Core;
 | 
			
		||||
 | 
			
		||||
namespace PoweredSoft.DynamicQuery
 | 
			
		||||
@ -26,32 +27,74 @@ namespace PoweredSoft.DynamicQuery
 | 
			
		||||
            var result = new GroupedQueryExecutionResult();
 | 
			
		||||
            result.TotalRecords = CurrentQueryable.LongCount();
 | 
			
		||||
 | 
			
		||||
            Criteria.Groups.ForEach(group =>
 | 
			
		||||
            {
 | 
			
		||||
                var finalGroup = InterceptGroup<T>(group);
 | 
			
		||||
                var groupCleanedPath = group.Path.Replace(".", "");
 | 
			
		||||
                CurrentQueryable = CurrentQueryable.GroupBy(QueryableUnderlyingType, gb =>
 | 
			
		||||
                {
 | 
			
		||||
                    gb.Path(finalGroup.Path);
 | 
			
		||||
                });
 | 
			
		||||
            // intercept groups in advance to avoid doing it more than once :)
 | 
			
		||||
            var finalGroups = Criteria.Groups.Select(g => InterceptGroup<T>(g)).ToList();
 | 
			
		||||
 | 
			
		||||
                CurrentQueryable = CurrentQueryable.Select(sb =>
 | 
			
		||||
            // get the aggregates.
 | 
			
		||||
            List<List<DynamicClass>> aggregateResults = null;
 | 
			
		||||
            if (Criteria.Aggregates.Any())
 | 
			
		||||
            {
 | 
			
		||||
                var previousGroups = new List<IGroup>();
 | 
			
		||||
                aggregateResults = finalGroups.Select(fg =>
 | 
			
		||||
                {
 | 
			
		||||
                    sb.ToList("Data");
 | 
			
		||||
                    sb.Key($"Group_{groupCleanedPath}", group.Path);
 | 
			
		||||
                    Criteria.Aggregates.ForEach(a =>
 | 
			
		||||
                    var groupExpression = CurrentQueryable.GroupBy(QueryableUnderlyingType, gb =>
 | 
			
		||||
                    {
 | 
			
		||||
                        var selectType = ResolveSelectFrom(a.Type);
 | 
			
		||||
                        var pathCleaned = a.Path.Replace(".", "");
 | 
			
		||||
                        sb.Aggregate(a.Path, selectType, $"Agg_{a.Type}_{pathCleaned}");
 | 
			
		||||
                        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 selectExpression = groupExpression.Select(sb =>
 | 
			
		||||
                    {
 | 
			
		||||
                        previousGroups.ForEach(pg => sb.Key(pg.Path));
 | 
			
		||||
                        sb.Key(fg.Path);
 | 
			
		||||
                        Criteria.Aggregates.ForEach(a =>
 | 
			
		||||
                        {
 | 
			
		||||
                            var selectType = ResolveSelectFrom(a.Type);
 | 
			
		||||
                            var pathCleaned = a.Path?.Replace(".", "");
 | 
			
		||||
                            sb.Aggregate(a.Path, selectType, $"Agg_{a.Type}_{pathCleaned}");
 | 
			
		||||
                        });
 | 
			
		||||
                    });
 | 
			
		||||
 | 
			
		||||
                    var aggregateResult = selectExpression.ToDynamicClassList();
 | 
			
		||||
                    previousGroups.Add(fg);
 | 
			
		||||
                    return aggregateResult;
 | 
			
		||||
                }).ToList();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // sorting.
 | 
			
		||||
            finalGroups.ForEach(fg =>
 | 
			
		||||
            {
 | 
			
		||||
                Criteria.Sorts.Insert(0, new Sort()
 | 
			
		||||
                {
 | 
			
		||||
                    Path = fg.Path,
 | 
			
		||||
                    Ascending = fg.Ascending
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            ApplySorting<T>();
 | 
			
		||||
            ApplyPaging<T>();
 | 
			
		||||
 | 
			
		||||
            // now get the data grouped.
 | 
			
		||||
            CurrentQueryable = CurrentQueryable.GroupBy(QueryableUnderlyingType, gb => finalGroups.ForEach(fg => gb.Path(fg.Path)));
 | 
			
		||||
            CurrentQueryable = CurrentQueryable.Select(sb =>
 | 
			
		||||
            {
 | 
			
		||||
                finalGroups.ForEach(fg => sb.Key(fg.Path));
 | 
			
		||||
                sb.ToList("Records");
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            var temp = CurrentQueryable.ToDynamicClassList();
 | 
			
		||||
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        protected virtual IQueryExecutionResult ExecuteNoGrouping<T>()
 | 
			
		||||
        {
 | 
			
		||||
            var result = new QueryExecutionResult();
 | 
			
		||||
@ -60,8 +103,8 @@ namespace PoweredSoft.DynamicQuery
 | 
			
		||||
            result.TotalRecords = CurrentQueryable.LongCount();
 | 
			
		||||
 | 
			
		||||
            // sorts and paging.
 | 
			
		||||
            ApplyNoGroupingSorts<T>();
 | 
			
		||||
            ApplyNoGroupingPaging<T>();
 | 
			
		||||
            ApplySorting<T>();
 | 
			
		||||
            ApplyPaging<T>();
 | 
			
		||||
            
 | 
			
		||||
            // the data.
 | 
			
		||||
            result.Data = CurrentQueryable.ToObjectList();
 | 
			
		||||
 | 
			
		||||
@ -49,7 +49,7 @@ namespace PoweredSoft.DynamicQuery
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        protected virtual void ApplyNoGroupingPaging<T>()
 | 
			
		||||
        protected virtual void ApplyPaging<T>()
 | 
			
		||||
        {
 | 
			
		||||
            if (!HasPaging)
 | 
			
		||||
                return;
 | 
			
		||||
@ -59,7 +59,7 @@ namespace PoweredSoft.DynamicQuery
 | 
			
		||||
            CurrentQueryable = q.Skip(skip).Take(Criteria.PageSize.Value);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected virtual void ApplyNoGroupingSorts<T>()
 | 
			
		||||
        protected virtual void ApplySorting<T>()
 | 
			
		||||
        {
 | 
			
		||||
            if (Criteria.Sorts?.Any() != true)
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user