Beispiel #1
0
        public void ItShouldBePossibleToSpecifyNullsFirstOrdering()
        {
            var stream =
                S.SelectNode(
                    S.Select(S.Star <Person>()),
                    S.From <Person>(),
                    orderBy: S.OrderBy(S.OrderClause(S.Col <Person>("Age"), Direction.Ascending, NullsOrdering.NullsFirst)));
            var result = SqlGen.SqlifyExpression(AnsiSql.Dialect, stream);

            Assert.That(result, Is.EqualTo("SELECT PersonRef.* FROM Person PersonRef ORDER BY PersonRef.Age ASC NULLS FIRST"));
        }
        public void ItShouldBePossibleToOrderDescendingByAColumn()
        {
            var stream =
                S.SelectNode(
                    S.Select(S.Star <Person>()),
                    S.From <Person>(),
                    orderBy: S.OrderBy(S.OrderClause(S.Col <Person>("Age"), Direction.Descending)));
            var result = SqlGen.SqlifyExpression(AnsiSql.Dialect, stream);

            Assert.That(result, Is.EqualTo(@"SELECT PersonRef.* FROM Person PersonRef ORDER BY PersonRef.Age DESC"));
        }
        public void ItShouldBePossibleToOrderBySeveralColumns()
        {
            var stream =
                S.SelectNode(
                    S.Select(S.Star <Person>(), S.Star <Car>()),
                    S.From <Person>(
                        S.Join <Person, Car>(JoinType.InnerJoin, S.BinExp(S.Col <Person>("Id"), BinaryOperation.Equal, S.Col <Car>("DriverId")))),
                    orderBy:
                    S.OrderBy(
                        S.OrderClause(S.Col <Person>("Age"), Direction.Ascending),
                        S.OrderClause(S.Col <Car>("Brand"), Direction.Descending)));
            var result = SqlGen.SqlifyExpression(AnsiSql.Dialect, stream);

            Assert.That(
                result,
                Is.EqualTo(
                    @"SELECT PersonRef.*, CarRef.* FROM Person PersonRef " +
                    "INNER JOIN Car CarRef ON PersonRef.Id = CarRef.DriverId " +
                    "ORDER BY PersonRef.Age ASC, CarRef.Brand DESC"));
        }