示例#1
0
        public void ItShouldBePossibleToDeleteWithASubQuery()
        {
            var stream =
                S.DeleteNode(
                    S.From <Car>(),
                    S.Where(
                        S.BinExp(
                            S.Col <Car>("DriverId"),
                            BinaryOperation.In,
                            S.SubExp(
                                S.Select(S.Col <Person>("Id")),
                                S.From <Person>(),
                                S.Where(S.BinExp(S.Col <Person>("Age"), BinaryOperation.LessThan, S.Const(18)))))));
            var result = SqlGen.SqlifyExpression(AnsiSql.Dialect, stream);

            Assert.That(
                result,
                Is.EqualTo(
                    "DELETE FROM Car CarRef " +
                    "WHERE CarRef.DriverId IN (" +
                    "SELECT PersonRef.Id " +
                    "FROM Person PersonRef " +
                    "WHERE PersonRef.Age < 18" +
                    ")"));
        }
示例#2
0
        public void ItShouldBePossibleToGenerateADeleteAllRowsFromTableStatement()
        {
            var stream =
                S.DeleteNode(S.From <Person>());
            var result = SqlGen.SqlifyExpression(AnsiSql.Dialect, stream);

            Assert.That(result, Is.EqualTo(@"DELETE FROM Person PersonRef"));
        }
示例#3
0
        public void ItShouldBePossibleToPutAWhereExpressionOnADeleteStatement()
        {
            var stream =
                S.DeleteNode(
                    S.From <Person>(),
                    S.Where(S.BinExp(S.Col <Person>("Age"), BinaryOperation.GreaterThan, S.Const(42))));
            var result = SqlGen.SqlifyExpression(AnsiSql.Dialect, stream);

            Assert.That(result, Is.EqualTo(@"DELETE FROM Person PersonRef WHERE PersonRef.Age > 42"));
        }
示例#4
0
        public void ItShouldBePossibleToUseAndAndOrOnAWhereStatementOnADeleteStatement()
        {
            var stream =
                S.DeleteNode(
                    S.From <Person>(),
                    S.Where(
                        S.BinExp(S.Col <Person>("Age"), BinaryOperation.GreaterThan, S.Const(42)),
                        S.And(S.BinExp(S.Col <Person>("Name"), BinaryOperation.Equal, S.Const("'Kalle'"))),
                        S.Or(S.BinExp(S.Col <Person>("Name"), BinaryOperation.Equal, S.Const("'Henrik'")))));
            var result = SqlGen.SqlifyExpression(AnsiSql.Dialect, stream);

            Assert.That(result,
                        Is.EqualTo(
                            "DELETE FROM Person PersonRef " +
                            "WHERE PersonRef.Age > 42 " +
                            "AND PersonRef.Name = 'Kalle' " +
                            "OR PersonRef.Name = 'Henrik'"));
        }