Exemple #1
0
        public virtual MigrationOperation CreateDeleteOperation(string migrationId)
        {
            DebugCheck.NotEmpty(migrationId);

            using (var connection = CreateConnection())
            {
                using (var context = CreateContext(connection))
                {
                    var historyRow
                        = new HistoryRow
                        {
                        MigrationId = migrationId,
                        ContextKey  = _contextKey
                        };

                    context.History.Attach(historyRow);
                    context.History.Remove(historyRow);

                    using (var commandTracer = new CommandTracer(context))
                    {
                        context.SaveChanges();

                        return(new HistoryOperation(commandTracer.DbCommands));
                    }
                }
            }
        }
        public virtual MigrationOperation CreateDeleteOperation(string migrationId)
        {
            DebugCheck.NotEmpty(migrationId);

            using (var connection = CreateConnection())
            {
                using (var context = CreateContext(connection))
                {
                    var historyRow
                        = new HistoryRow
                        {
                        MigrationId = migrationId.RestrictTo(_migrationIdMaxLength),
                        ContextKey  = _contextKey
                        };

                    context.History.Attach(historyRow);
                    context.History.Remove(historyRow);

                    using (var commandTracer = new CommandTracer(context))
                    {
                        context.SaveChanges();

                        return(new HistoryOperation(
                                   commandTracer.CommandTrees.OfType <DbModificationCommandTree>().ToList()));
                    }
                }
            }
        }
Exemple #3
0
        public virtual MigrationOperation CreateDeleteOperation(string migrationId)
        {
            DbConnection connection = (DbConnection)null;

            try
            {
                connection = this.CreateConnection();
                using (HistoryContext context = this.CreateContext(connection, (string)null))
                {
                    HistoryRow entity = new HistoryRow()
                    {
                        MigrationId = migrationId.RestrictTo(this._migrationIdMaxLength),
                        ContextKey  = this._contextKey
                    };
                    context.History.Attach(entity);
                    context.History.Remove(entity);
                    using (CommandTracer commandTracer = new CommandTracer((DbContext)context))
                    {
                        context.SaveChanges();
                        return((MigrationOperation) new HistoryOperation((IList <DbModificationCommandTree>)commandTracer.CommandTrees.OfType <DbModificationCommandTree>().ToList <DbModificationCommandTree>(), (object)null));
                    }
                }
            }
            finally
            {
                this.DisposeConnection(connection);
            }
        }
Exemple #4
0
        public void Generate_can_output_delete_history_statement()
        {
            var migrationSqlGenerator = new SqlCeMigrationSqlGenerator();

            using (var historyContext = new HistoryContext())
            {
                var historyRow
                    = new HistoryRow
                          {
                              MigrationId = "House Lannister",
                              ContextKey = "The pointy end"
                          };

                historyContext.History.Attach(historyRow);
                historyContext.History.Remove(historyRow);

                using (var commandTracer = new CommandTracer(historyContext))
                {
                    historyContext.SaveChanges();

                    var deleteHistoryOperation
                        = new HistoryOperation(commandTracer.CommandTrees.OfType<DbModificationCommandTree>().ToList());

                    var sql
                        = migrationSqlGenerator
                            .Generate(new[] { deleteHistoryOperation }, "4.0")
                            .Single();

                    Assert.Equal(@"DELETE [__MigrationHistory]
WHERE (([MigrationId] = N'House Lannister') AND ([ContextKey] = N'The pointy end'))", sql.Sql.Trim());
                }
            }
        }
        public virtual MigrationOperation CreateDeleteOperation(string migrationId)
        {
            DebugCheck.NotEmpty(migrationId);

            DbConnection connection = null;
            try
            {
                connection = CreateConnection();

                using (var context = CreateContext(connection))
                {
                    var historyRow
                        = new HistoryRow
                            {
                                MigrationId = migrationId.RestrictTo(_migrationIdMaxLength),
                                ContextKey = _contextKey
                            };

                    context.History.Attach(historyRow);
                    context.History.Remove(historyRow);

                    using (var commandTracer = new CommandTracer(context))
                    {
                        context.SaveChanges();

                        return new HistoryOperation(
                            commandTracer.CommandTrees.OfType<DbModificationCommandTree>().ToList());
                    }
                }
            }
            finally
            {
                DisposeConnection(connection);
            }
        }
        public virtual MigrationOperation CreateDeleteOperation(string migrationId)
        {
            DebugCheck.NotEmpty(migrationId);

            using (var connection = CreateConnection())
            {
                using (var context = CreateContext(connection))
                {
                    var historyRow
                        = new HistoryRow
                        {
                            MigrationId = migrationId,
                            ContextKey = _contextKey
                        };

                    context.History.Attach(historyRow);
                    context.History.Remove(historyRow);

                    using (var commandTracer = new CommandTracer(context))
                    {
                        context.SaveChanges();

                        return new HistoryOperation(commandTracer.DbCommands);
                    }
                }
            }
        }