예제 #1
0
        public void two_OrderClause_instances_with_same_properties_are_equals(OrderClause orderClause)
        {
            OrderClause otherOrderClause;

            otherOrderClause = new OrderClause(orderClause.Column, orderClause.Direction);

            otherOrderClause.Equals(orderClause).Should().BeTrue();
        }
예제 #2
0
        private string GetOrderClauseInner <T>(
            OrderClause <T> clause,
            FetchNode rootNode,
            Func <IColumn, FetchNode, string> aliasRewriter,
            Func <IColumn, FetchNode, string> nameRewriter,
            out bool isRootPrimaryKeyClause)
        {
            var lambdaExpression = clause.Expression as LambdaExpression;

            if (lambdaExpression == null)
            {
                throw new InvalidOperationException("OrderBy clauses must be LambdaExpressions");
            }

            var node = this.VisitExpression(lambdaExpression.Body, rootNode);
            var sb   = new StringBuilder();

            if (node == null)
            {
                var column = this.configuration.GetMap <T>().Columns[((MemberExpression)lambdaExpression.Body).Member.Name];
                this.dialect.AppendQuotedName(sb, nameRewriter != null ? nameRewriter(column, node) : column.DbName);
                sb.Append(" ").Append(clause.Direction == ListSortDirection.Ascending ? "asc" : "desc");
                isRootPrimaryKeyClause = column.IsPrimaryKey;
            }
            else
            {
                IColumn column = null;
                if (ReferenceEquals(node, rootNode))
                {
                    column = this.configuration.GetMap <T>().Columns[((MemberExpression)lambdaExpression.Body).Member.Name];
                    isRootPrimaryKeyClause = column.IsPrimaryKey;
                }
                else
                {
                    if (node.Column.Relationship == RelationshipType.ManyToOne)
                    {
                        column = node.Column.ParentMap.Columns[((MemberExpression)lambdaExpression.Body).Member.Name];
                    }
                    else if (node.Column.Relationship == RelationshipType.OneToOne)
                    {
                        column = node.Column.OppositeColumn.Map.Columns[((MemberExpression)lambdaExpression.Body).Member.Name];
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }

                    isRootPrimaryKeyClause = false;
                }

                sb.Append(aliasRewriter != null ? aliasRewriter(column, node) : node.Alias).Append(".");
                this.dialect.AppendQuotedName(sb, nameRewriter != null ? nameRewriter(column, node) : column.DbName);
                sb.Append(" ").Append(clause.Direction == ListSortDirection.Ascending ? "asc" : "desc");
            }

            return(sb.ToString());
        }
        public static T setOrder <T>(this T query, string column, OrderDirection direction = OrderDirection.Ascendant) where T : IOrderedQuery
        {
            OrderClause orderClause;

            orderClause = new OrderClause(column, direction);
            query.Order.Add(orderClause);

            return(query);
        }
        public void SimpleClauseDescendingCorrect()
        {
            Expression <Func <Post, string> > cls = p => p.Title;
            var  clause = new OrderClause <Post>(cls, ListSortDirection.Descending);
            var  writer = new OrderClauseWriter(new CustomConfig(), new SqlServerDialect());
            bool containsPrimaryKeyClause = false;
            var  result = writer.GetOrderClause(clause, null, out containsPrimaryKeyClause);

            Assert.Equal("[Title] desc", result);
        }
        public void OrderByPrimaryKeyContainsPrimaryKeyClause()
        {
            Expression <Func <Post, int> > cls = p => p.PostId;
            var  clause = new OrderClause <Post>(cls, ListSortDirection.Ascending);
            var  writer = new OrderClauseWriter(new CustomConfig(), new SqlServerDialect());
            bool containsPrimaryKeyClause = false;
            var  result = writer.GetOrderClause(clause, null, out containsPrimaryKeyClause);

            Assert.True(containsPrimaryKeyClause);
        }
예제 #6
0
        public void new_OrderClause_has_expected_values(string columnName, OrderDirection orderDirection)
        {
            OrderClause orderClause;

            orderClause = new OrderClause(columnName, orderDirection);

            orderClause.Should().NotBeNull();
            orderClause.Column.Should().Be(columnName);
            orderClause.Direction.Should().Be(orderDirection);
        }
예제 #7
0
        /// <summary>
        /// Ham khoi tao gia tri mac dinh cho cac bien
        /// </summary>
        private void Init()
        {
            FieldsField = FieldsField.Equals("") ? nameof(Entity.MSSQL_QLDN_MAIN.Entity.NguoiDung.NguoiDungId) : FieldsField;

            OrderClause = OrderClause.Equals("") ? nameof(Entity.MSSQL_QLDN_MAIN.Entity.NguoiDung.NguoiDungId) : OrderClause;

            Skip = Skip != null ? Skip.Value : 0;

            Take = Take != null ? Take.Value : 100;
        }
예제 #8
0
        /// <summary>
        /// Ham khoi tao gia tri mac dinh cho cac bien
        /// </summary>
        private void Init()
        {
            FieldsField = FieldsField.Equals("") ? nameof(Entity.MSSQL_QLDN_QLNS.Entity.NhanVien.NhanVienId) : FieldsField;

            OrderClause = OrderClause.Equals("") ? nameof(Entity.MSSQL_QLDN_QLNS.Entity.NhanVien.NhanVienId) : OrderClause;

            Skip = Skip != null ? Skip.Value : 0;

            Take = Take != null ? Take.Value : 100;
        }
        public void OrderByForeignKeyDesc()
        {
            Expression <Func <Post, Blog> > cls = p => p.Blog;
            var  clause = new OrderClause <Post>(cls, ListSortDirection.Descending);
            var  writer = new OrderClauseWriter(new CustomConfig(), new SqlServerDialect());
            bool containsPrimaryKeyClause = false;
            var  result = writer.GetOrderClause(clause, null, out containsPrimaryKeyClause);

            Assert.Equal("[BlogId] desc", result);
        }
예제 #10
0
        /// <summary>
        /// Ham khoi tao gia tri mac dinh cho cac bien
        /// </summary>
        private void Init()
        {
            FieldsField = FieldsField.Equals("") ? nameof(Entity.MSSQL_QLDN_QLNS.Entity.NghiPhep.NghiPhepId) : FieldsField;

            WhereClause = WhereClause.Equals("") ? "" : WhereClause;

            OrderClause = OrderClause.Equals("") ? nameof(Entity.MSSQL_QLDN_QLNS.Entity.NghiPhep.NghiPhepId) : OrderClause;

            Skip = Skip != null ? Skip.Value : 0;

            Take = Take != null ? Take.Value : 100;
        }
예제 #11
0
            public PlanOrderBuilder(Query input, OrderClause order)
            {
                _input = input;
                _order = order;

                _underlyingSelect = new List <Column>();
                _orderColumns     = new List <(Expression Expression, OrderDirection Direction)>();

                _input.Select.Switch(
                    BuildStar,
                    BuildList
                    );
            }
예제 #12
0
        public static void AssertEqual(OrderClause expected, OrderClause actual)
        {
            Assert.Equal(expected.Columns.Count, actual.Columns.Count);

            for (var i = 0; i < expected.Columns.Count; i++)
            {
                var(expectedExpression, expectedDirection) = expected.Columns[i];
                var(actualExpression, actualDirection)     = actual.Columns[i];

                Assert.Equal(expectedExpression, actualExpression);
                Assert.Equal(expectedDirection, actualDirection);
            }
        }
    private IQueryable <T> _source = ...    // Don't know how this works
                                     public IEnumerable <T> Query(OrderClause <T> clauseList)
    {
        // Needs validation, e.g. null-reference or empty clause-list.
        var clauses = clauseList.OrderByClauses;

        IOrderedQueryable <T> result = Queryable.OrderBy(_source,
                                                         (dynamic)clauses.First());

        foreach (var clause in clauses.Skip(1))
        {
            result = Queryable.ThenBy(result, (dynamic)clause);
        }

        return(result.ToList());
    }
예제 #14
0
        public override void CopyOrderTo(Span <OrderClause> order)
        {
            var node = Tail;
            int index = 0, groupStartIndex = 0;

            while (node is object)
            {
                var value = new OrderClause(node.Expression, Reversed ? !node.Ascending : node.Ascending);
                order[index++] = value;
                if (node.NewGroup)
                {
                    Reverse(order, groupStartIndex, index);
                    groupStartIndex = index;
                }
                node = node.Head;
            }
            Reverse(order, groupStartIndex, index);
예제 #15
0
        public string GetOrderClause <T>(
            OrderClause <T> clause,
            FetchNode rootNode,
            Func <IColumn, FetchNode, string> aliasRewriter,
            Func <IColumn, FetchNode, string> nameRewriter,
            out bool isRootPrimaryKeyClause)
        {
            if (aliasRewriter == null)
            {
                throw new ArgumentNullException("aliasRewriter");
            }

            if (nameRewriter == null)
            {
                throw new ArgumentNullException("nameRewriter");
            }

            return(this.GetOrderClauseInner(clause, rootNode, aliasRewriter, nameRewriter, out isRootPrimaryKeyClause));
        }
예제 #16
0
        /// <summary>
        ///     Generates the SQL text for the whole query.
        /// </summary>
        /// <param name="sb">The SQL text formatter.</param>
        public void RenderSql(SqlBuilderContext sb)
        {
            SelectClause.RenderSql(sb);

            FromClause.RenderSql(sb);

            WhereClause.RenderSql(sb, this);

            GroupByClause.RenderSql(sb);

            HavingClause.RenderSql(sb);

            OrderClause.RenderSql(sb);

            if (!string.IsNullOrEmpty(ForClause))
            {
                sb.AppendOnNewLine(ForClause);
            }
        }
예제 #17
0
        /// <summary>
        /// Ham khoi tao gia tri mac dinh cho cac bien
        /// </summary>
        private void Init()
        {
            var fieldefault = nameof(Entity.MSSQL_QLDN_MAIN.Entity.CauHinhFormCot.CauHinhFormCotId);

            fieldefault += "," + nameof(Entity.MSSQL_QLDN_MAIN.Entity.CauHinhFormCot.MaForm);
            fieldefault += "," + nameof(Entity.MSSQL_QLDN_MAIN.Entity.CauHinhFormCot.MaCot);
            fieldefault += "," + nameof(Entity.MSSQL_QLDN_MAIN.Entity.CauHinhFormCot.TenCot);
            fieldefault += "," + nameof(Entity.MSSQL_QLDN_MAIN.Entity.CauHinhFormCot.TenCotMacDinh);
            fieldefault += "," + nameof(Entity.MSSQL_QLDN_MAIN.Entity.CauHinhFormCot.HienThiYN);
            fieldefault += "," + nameof(Entity.MSSQL_QLDN_MAIN.Entity.CauHinhFormCot.ThuTu);
            fieldefault += "," + nameof(Entity.MSSQL_QLDN_MAIN.Entity.CauHinhFormCot.CtrVersion);
            FieldsField  = FieldsField.Equals("") ? fieldefault : FieldsField;

            OrderClause = OrderClause.Equals("") ? nameof(Entity.MSSQL_QLDN_MAIN.Entity.CauHinhFormCot.ThuTu) : OrderClause;

            Skip = Skip != null ? Skip.Value : 0;

            Take = Take != null ? Take.Value : 100;
        }
예제 #18
0
            static IEnumerable <OrderClause <T> > BuildOrderClauses(ISort <T> sort)
            {
                switch (sort)
                {
                case Sort <T> singleSort:
                    yield return(OrderClause <T> .Create(singleSort.Expression.ToLambda <T>(), singleSort.Direction));

                    break;

                case MultiSort <T> multiSort:
                    foreach (Sort <T> item in multiSort.Sorts)
                    {
                        foreach (OrderClause <T> order in item.ToOrderClause())
                        {
                            yield return(order);
                        }
                    }
                    break;
                }
            }
예제 #19
0
        /*
         *      BNF:
         *      <order by clause> ::=
         *              order by <order column expression commalist>
         *
         *      <order column expression> ::=
         *              <column identifier> [asc | desc]
         *
         *      <column identifier> ::=
         *              <qualified identifier>
         */
        protected OrderClause OrderClause(Lexer lexer)
        {
            lexer.NextToken();
            lexer.NextToken().CheckSymbol(Keywords.By);
            OrderClause clause = new OrderClause();

            while (true)
            {
                clause.Columns.Add(OrderFieldExpression(lexer));
                if (lexer.PeekTokenSymbol(1) == Keywords.ListSeparator)
                {
                    lexer.NextToken();
                }
                else
                {
                    break;
                }
            }
            return(clause);
        }
예제 #20
0
 public string GetOrderClause <T>(OrderClause <T> clause, FetchNode rootNode, out bool isRootPrimaryKeyClause)
 {
     return(this.GetOrderClauseInner(clause, rootNode, null, null, out isRootPrimaryKeyClause));
 }
예제 #21
0
 public void two_OrderClause_instances_with_different_properties_are_not_equals(OrderClause orderClause1, OrderClause orderClause2)
 {
     orderClause1.Equals(orderClause2).Should().BeFalse();
 }
예제 #22
0
 public AlreadyAddedOrderClauseQueryException(OrderClause item)
     : base($"The order clause is already part of the order colecction.")
 {
     this.OrderClause = item;
 }