예제 #1
0
        public void ItCanDoASimpleUnionAll()
        {
            var expr =
                SetOperations.UnionAll(
                    Select.Star <Person>()
                    .From <Person>()
                    .Where <Person>(p => p.Age > 42),
                    Select.Star <Person>()
                    .From <Person>()
                    .Where <Person>(p => p.Name == "Kalle")
                    );
            var result = expr.ToSqlExpression();

            Assert.That(result, Is.EqualTo(TokenGeneration_SetOperationTests_Results.simpleUnionAllExpression));
        }
예제 #2
0
        public void ItShouldBePossibleToDoARecursiveCommonTableExpression()
        {
            var expr =
                With.Table <RecursivePerson>(
                    SetOperations.UnionAll(
                        Select.Column <Person>(p => new { Level = 0, p.Name, p.ParentId, })
                        .From <Person>()
                        .Where <Person>(p => p.Name == "Kalle"),
                        Select.Column <RecursivePerson>(rp => new { Level = rp.Level + 1 })
                        .Column <Person>(p => new { p.Name, p.ParentId })
                        .From <Person>()
                        .InnerJoin <Person, RecursivePerson>((p, rp) => p.Id == rp.ParentId)))
                .Query(Select.Star <RecursivePerson>().From <RecursivePerson>());
            var result = expr.ToSqlExpression();

            Assert.That(result, Is.EqualTo(TokenGeneration_CommonTableExpressions_Results.recursiveCommonTableExpression));
        }