Esempio n. 1
0
 public void SingleDeleteWorks() {
     var deleteWriter = new DeleteWriter(new SqlServerDialect(), MakeConfig());
     var post = new Post { PostId = 1 };
     var result = deleteWriter.GenerateSql(new[] { post });
     Debug.Write(result.Sql);
     Assert.Equal("delete from [Posts] where [PostId] in (@p_1)", result.Sql);
 }
Esempio n. 2
0
        public int DeleteMany(IQueryable <TEntity> source)
        {
            var query = QueryVisitor <TEntity> .CreateModel(source.Expression,
                                                            x => ((Table <TEntity>)x).Name);

            return(Command.Create(DeleteWriter <TEntity> .CreateStatement(
                                      new Delete(_table, query.Select, true), _map), _profiler).
                   ExecuteNonQuery(_connectionManager));
        }
Esempio n. 3
0
        public void SingleDeleteWorks()
        {
            var deleteWriter = new DeleteWriter(new SqlServerDialect(), MakeConfig());
            var post         = new Post {
                PostId = 1
            };
            var result = deleteWriter.GenerateSql(new[] { post });

            Debug.Write(result.Sql);
            Assert.Equal("delete from [Posts] where [PostId] in (@p_1)", result.Sql);
        }
Esempio n. 4
0
        public void Delete_Multi_Test()
        {
            var delete    = new Delete(TableName, Operator.Create.FieldAndConstant("Age", Operator.OperatorType.GreaterThan, 20), true);
            var statement = DeleteWriter <Entity> .CreateStatement(delete, Map);

            statement.Result.ShouldEqual(Statement.ResultType.None);
            statement.Parameters.Count.ShouldEqual(1);
            statement.Parameters.First().Value.ShouldEqual(20);
            statement.Text.ShouldEqual(string.Format("DELETE FROM [{0}] WHERE ([age] > @{1})", TableName,
                                                     statement.Parameters.First().Key));
        }
Esempio n. 5
0
        public void Delete_Single_Test()
        {
            var delete    = new Delete(TableName, Operator.Create.FieldEqualsConstant("Id", Guid.Empty), false);
            var statement = DeleteWriter <Entity> .CreateStatement(delete, Map);

            statement.Result.ShouldEqual(Statement.ResultType.None);
            statement.Parameters.Count.ShouldEqual(1);
            statement.Parameters.First().Value.ShouldEqual(Guid.Empty);
            statement.Text.ShouldEqual(string.Format("DELETE TOP (1) FROM [{0}] WHERE ([id] = @{1})", TableName,
                                                     statement.Parameters.First().Key));
        }
Esempio n. 6
0
        public void should_render_multi_delete_by_query_sql()
        {
            var delete = new Delete(TableName, new Select {
                From = { Type     = Data.DataType.Table, Table = new Table {
                             Name = TableName
                         } },
                Where = Operator.Create.FieldAndConstant("Age", Operator.OperatorType.GreaterThan, 20)
            }, true);
            var statement = DeleteWriter <Entity> .CreateStatement(delete, Map);

            statement.Result.ShouldEqual(Statement.ResultType.None);
            statement.Parameters.Count.ShouldEqual(1);
            statement.Parameters.First().Value.ShouldEqual(20);
            statement.Text.ShouldEqual(string.Format("DELETE FROM [{0}] WHERE EXISTS (SELECT [id] FROM (SELECT * FROM [{0}] {1} WHERE ([age] > @{2})) AS [__SubQuery__] WHERE [__SubQuery__].[id] = [{0}].[id])",
                                                     TableName, delete.Select.From.Alias, statement.Parameters.First().Key));
        }
Esempio n. 7
0
 public void EmptyDeleteThrows() {
     var deleteWriter = new DeleteWriter(new SqlServerDialect(), MakeConfig());
     Assert.Throws<ArgumentOutOfRangeException>(() => deleteWriter.GenerateSql(new Post[0]));
 }
Esempio n. 8
0
        public void EmptyDeleteThrows()
        {
            var deleteWriter = new DeleteWriter(new SqlServerDialect(), MakeConfig());

            Assert.Throws <ArgumentOutOfRangeException>(() => deleteWriter.GenerateSql(new Post[0]));
        }
Esempio n. 9
0
 private int Delete(Operator filter, bool multiDelete)
 {
     return(Command.Create(DeleteWriter <TEntity> .CreateStatement(
                               new Delete(_table, filter, multiDelete), _map), _profiler).
            ExecuteNonQuery(_connectionManager));
 }