/// <inheritdoc />
        public virtual TQuery GroupBy(Expression <Func <TSource, object> > property)
        {
            if (property != null)
            {
                IProjection projection = ProjectionHelper
                                         .GetProjection
                                         (
                    property.Body,
                    new HelperContext(Data, property, HelperType.GroupBy)
                                         );

                if (projection != null)
                {
                    if (projection.IsGrouped || projection.IsAggregate)
                    {
                        throw new InvalidOperationException(
                                  "Cannot use an aggregate or grouped projection with GroupBy");
                    }

                    GroupBys.Add(new FqGroupByProjection(projection, false));
                }
            }

            return(Query);
        }
Exemple #2
0
 public QueryExpression GroupBy(params string[] propertyNames)
 {
     foreach (string propertyName in propertyNames)
     {
         GroupBys.Add(propertyName);
     }
     return(this);
 }
Exemple #3
0
 public QueryExpression GroupBy(params IPropertyExpression[] propertys)
 {
     foreach (IPropertyExpression property in propertys)
     {
         GroupBys.Add(new GroupExpression(property.PropertyName));
     }
     return(this);
 }
Exemple #4
0
        /// <summary>
        /// 构建 Select 语句信息
        /// </summary>
        /// <param name="mainTable">表</param>
        public SelectStatement(ITable mainTable)
        {
            MainTable = mainTable;

            Columns  = new SelectColumns();
            Joins    = new Joins();
            Where    = new Conditions();
            OrderBys = new OrderBys();
            GroupBys = new GroupBys();
            Having   = new Conditions();
        }
Exemple #5
0
        private string BuildOutput(bool includeSelection = true)
        {
            var sb = new StringBuilder();

            var offset = Limit?.Offset ?? 0;
            var fetch  = Limit?.Fetch ?? 0;

            if (includeSelection)
            {
                var topStr = offset == 0 && fetch > 0 ? $"top({fetch}) " : "";
                sb.Append($"select {topStr}{Selection}");
            }

            if (From != null)
            {
                sb.AppendLine();
                sb.Append($"from {From}");
            }

            if (Joins.Count > 0)
            {
                sb.AppendLine();
                sb.Append($"{string.Join(Environment.NewLine, Joins)}");
            }

            if (Where != null)
            {
                sb.AppendLine();
                sb.Append($"where {Where}");
            }

            if (GroupBys.Any())
            {
                sb.AppendLine();
                sb.Append($"group by {GroupBys}");
            }

            if (OrderBys.Any())
            {
                sb.AppendLine();
                sb.Append($"order by {string.Join(", ", OrderBys)}");
            }

            if (Limit != null && Limit.Offset > 0)
            {
                sb.AppendLine();
                sb.Append($"{Limit}");
            }

            sb.AppendLine();

            return(sb.ToString());
        }
Exemple #6
0
        private string BuildOutput(bool includeSelection = true)
        {
            var sb = new StringBuilder();

            if (includeSelection)
            {
                sb.Append($"select {Selection}");
            }

            if (From != null)
            {
                sb.AppendLine();
                sb.Append($"from {From}");
            }

            if (Joins.Count > 0)
            {
                sb.AppendLine();
                sb.Append($"{string.Join(Environment.NewLine, Joins)}");
            }

            if (Where != null)
            {
                sb.AppendLine();
                sb.Append($"where {Where}");
            }

            if (GroupBys.Any())
            {
                sb.AppendLine();
                sb.Append($"group by {GroupBys}");
            }

            if (OrderBys.Any())
            {
                sb.AppendLine();
                sb.Append($"order by {string.Join(", ", OrderBys)}");
            }

            sb.AppendLine();

            return(sb.ToString());
        }
        public override IExplore Expolore(DelegateExpessionExplorer del)
        {
            List <TableClause> Tables2 = new List <TableClause>();

            Tables.ForEach(a =>
            {
                TableClause g2 = (TableClause)a.Expolore(del);
                if (g2 != null)
                {
                    Tables2.Add(g2);
                }
            });
            Tables.Replace(Tables2);
            List <ColumnClause> Columns2 = new List <ColumnClause>();

            Columns.ForEach(a =>
            {
                ColumnClause c = (ColumnClause)a.Expolore(del);
                if (c != null)
                {
                    Columns2.Add(c);
                }
            }
                            );
            Columns.Replace(Columns2);
            if (WhereExpr != null)
            {
                WhereExpr = (Expression)WhereExpr.Expolore(del);
            }
            if (GroupBys != null)
            {
                List <GroupByClause> GroupBys2 = new List <GroupByClause>();
                GroupBys.ForEach(a =>
                {
                    GroupByClause g2 = (GroupByClause)a.Expolore(del);
                    if (g2 != null)
                    {
                        GroupBys2.Add(g2);
                    }
                });
                GroupBys.Replace(GroupBys2);
            }
            if (Having != null)
            {
                Having = (Expression)Having.Expolore(del);
            }
            if (OrderBys != null)
            {
                List <OrderByClause> OrderBys2 = new List <OrderByClause>();
                OrderBys.ForEach(a =>
                {
                    OrderByClause g2 = (OrderByClause)a.Expolore(del);
                    if (g2 != null)
                    {
                        OrderBys2.Add(g2);
                    }
                });
                OrderBys.Replace(OrderBys2);
            }



            if (ExtSelects != null && ExtSelects.Count > 0)
            {
                var ExtSelects2 = new TokenList <ExtSelectClause>(this);
                foreach (var e in ExtSelects)
                {
                    var t = (ExtSelectClause)e.Expolore(del);
                    if (t != null)
                    {
                        ExtSelects2.Add(t);
                    }
                }
                ExtSelects = ExtSelects2;
            }
            return(base.Expolore(del));
        }
 public void AdicionarAgrupamento(string agrupamento)
 {
     GroupBys.Add(agrupamento);
 }
Exemple #9
0
 public void AppendGroupBy(IQueryableColumn groupByColumn)
 {
     GroupBys.Add(groupByColumn);
 }
        /// <inheritdoc />
        public virtual TQuery ClearGroupBys()
        {
            GroupBys.Clear();

            return(Query);
        }