public static DbSelectExpression RemoveGroupExpression(this DbSelectExpression select, Expression expression)
        {
            if (select.GroupBy != null && select.GroupBy.Count > 0)
            {
                var groupby = new List <Expression>(select.GroupBy);

                if (groupby != null)
                {
                    groupby.Remove(expression);
                }

                return(select.SetGroupBy(groupby));
            }

            return(select);
        }
        public static DbSelectExpression AddGroupExpression(this DbSelectExpression select, Expression expression)
        {
            var groupby = new List <Expression>();

            if (select.GroupBy != null)
            {
                groupby.AddRange(select.GroupBy);
            }

            if (groupby != null)
            {
                groupby.Add(expression);
            }

            return(select.SetGroupBy(groupby));
        }