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(); }
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); }
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); }
/// <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; }
/// <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); }
/// <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; }
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 ); }
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()); }
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);
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)); }
/// <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); } }
/// <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; }
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; } }
/* * 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); }
public string GetOrderClause <T>(OrderClause <T> clause, FetchNode rootNode, out bool isRootPrimaryKeyClause) { return(this.GetOrderClauseInner(clause, rootNode, null, null, out isRootPrimaryKeyClause)); }
public void two_OrderClause_instances_with_different_properties_are_not_equals(OrderClause orderClause1, OrderClause orderClause2) { orderClause1.Equals(orderClause2).Should().BeFalse(); }
public AlreadyAddedOrderClauseQueryException(OrderClause item) : base($"The order clause is already part of the order colecction.") { this.OrderClause = item; }