示例#1
0
        public void Can_detect_renamed_many_to_many_table()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity<ManyManySelfRef>();

            var model1 = modelBuilder.Build(ProviderInfo);
            
            modelBuilder.Entity<ManyManySelfRef>().ToTable("Renamed");

            var model2 = modelBuilder.Build(ProviderInfo);

            var operations
                = new EdmModelDiffer().Diff(model1.GetModel(), model2.GetModel());

            var tableRename = (RenameTableOperation)operations.Single();

            Assert.Equal("dbo.ManyManySelfRefs", tableRename.Name);
            Assert.Equal("Renamed", tableRename.NewName);
        }
示例#2
0
        public void Should_not_detect_pk_change_when_pk_column_renamed()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity <OrderLine>();

            var model1 = modelBuilder.Build(ProviderInfo);

            modelBuilder = new DbModelBuilder();

            modelBuilder.Entity <OrderLine>().Property(ol => ol.Id).HasColumnName("pk_ID");

            var model2 = modelBuilder.Build(ProviderInfo);

            var operations = new EdmModelDiffer().Diff(
                model1.GetModel(), model2.GetModel());

            Assert.Equal(1, operations.Count());
            Assert.True(operations.Single() is RenameColumnOperation);
        }
示例#3
0
        public void Can_detect_simple_table_rename()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity<MigrationsCustomer>();

            var model1 = modelBuilder.Build(ProviderInfo);

            modelBuilder.Entity<MigrationsCustomer>().ToTable("Customer");

            var model2 = modelBuilder.Build(ProviderInfo);

            var operations 
                = new EdmModelDiffer().Diff(model1.GetModel(), model2.GetModel());

            var tableRename = (RenameTableOperation)operations.Single();

            Assert.Equal("dbo.MigrationsCustomers", tableRename.Name);
            Assert.Equal("Customer", tableRename.NewName);
        }
示例#4
0
        public void Should_not_detect_pk_change_when_pk_column_renamed()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity<OrderLine>();

            var model1 = modelBuilder.Build(ProviderInfo);

            modelBuilder = new DbModelBuilder();

            modelBuilder.Entity<OrderLine>().Property(ol => ol.Id).HasColumnName("pk_ID");

            var model2 = modelBuilder.Build(ProviderInfo);

            var operations = new EdmModelDiffer().Diff(
                model1.GetModel(), model2.GetModel());

            Assert.Equal(1, operations.Count());
            Assert.True(operations.Single() is RenameColumnOperation);
        }
示例#5
0
        public void Table_rename_does_not_trigger_index_drop_and_create()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity<MigrationsCustomer>()
                .Property(e => e.Id)
                .HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute("Bella")));

            var model1 = modelBuilder.Build(ProviderInfo);

            modelBuilder.Entity<MigrationsCustomer>()
                .ToTable("Customer")
                .Property(e => e.Id)
                .HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute("Bella")));

            var model2 = modelBuilder.Build(ProviderInfo);

            var operations= new EdmModelDiffer().Diff(model1.GetModel(), model2.GetModel());

            Assert.IsType<RenameTableOperation>(operations.Single());
        }
示例#6
0
        public void Can_detect_table_move_when_ospace_type_renamed_on_one_side_of_many_to_many()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder
                .Entity<TableRenameManyManyLeft1>()
                .ToTable("Left")
                .HasMany(l => l.Rights)
                .WithMany(r => r.Lefts)
                .Map(
                    m =>
                    {
                        m.MapLeftKey("LeftId");
                        m.MapRightKey("RightId");
                        m.ToTable("Join", "foo");
                    });

            modelBuilder
                .Entity<OSpaceRenames_v1.TableRenameManyManyRight>()
                .ToTable("Right");

            var model1 = modelBuilder.Build(ProviderInfo);

            modelBuilder = new DbModelBuilder();

            modelBuilder
                .Entity<TableRenameManyManyLeft2>()
                .ToTable("Left")
                .HasMany(l => l.Rights)
                .WithMany(r => r.Lefts)
                .Map(
                    m =>
                    {
                        m.MapLeftKey("LeftId");
                        m.MapRightKey("RightId");
                        m.ToTable("Join", "bar");
                    });

            modelBuilder
                .Entity<OSpaceRenames_v2.TableRenameManyManyRight>()
                .ToTable("Right");

            var model2 = modelBuilder.Build(ProviderInfo);

            var operations
                = new EdmModelDiffer().Diff(model1.GetModel(), model2.GetModel());

            Assert.Equal(1, operations.Count());

            var moveTableOperation = (MoveTableOperation)operations.Single();

            Assert.Equal("foo.Join", moveTableOperation.Name);
            Assert.Equal("bar", moveTableOperation.NewSchema);
        }
示例#7
0
        public void Can_detect_table_move_when_ospace_type_renamed()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity<TableRename1>().ToTable("foo.TableRename1");

            var model1 = modelBuilder.Build(ProviderInfo);

            modelBuilder = new DbModelBuilder();

            modelBuilder.Entity<TableRename2>().ToTable("bar.TableRename1");

            var model2 = modelBuilder.Build(ProviderInfo);

            var operations
                = new EdmModelDiffer().Diff(model1.GetModel(), model2.GetModel());

            var moveTableOperation = (MoveTableOperation)operations.Single();

            Assert.Equal("foo.TableRename1", moveTableOperation.Name);
            Assert.Equal("bar", moveTableOperation.NewSchema);
        }
示例#8
0
        public void Can_detect_table_rename_when_ospace_type_renamed_table_splitting()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity<TableRenameTableSplit1>();
            modelBuilder.Entity<TableRenameTableSplit1>().HasRequired(t => t.Payload).WithRequiredPrincipal();
            modelBuilder.Entity<TableRenameTableSplitPayload1>().ToTable("TableRenameTableSplit1");

            var model1 = modelBuilder.Build(ProviderInfo);

            modelBuilder = new DbModelBuilder();

            modelBuilder.Entity<TableRenameTableSplit2>();
            modelBuilder.Entity<TableRenameTableSplit2>().HasRequired(t => t.Payload).WithRequiredPrincipal();
            modelBuilder.Entity<TableRenameTableSplitPayload2>().ToTable("TableRenameTableSplit2");

            var model2 = modelBuilder.Build(ProviderInfo);

            var operations
                = new EdmModelDiffer().Diff(model1.GetModel(), model2.GetModel());

            var renameTableOperation = (RenameTableOperation)operations.Single();

            Assert.Equal("dbo.TableRenameTableSplit1", renameTableOperation.Name);
            Assert.Equal("TableRenameTableSplit2", renameTableOperation.NewName);
        }
示例#9
0
        public void Diffing_TPH_models_with_discriminator_based_on_nullability_rather_than_value_works()
        {
            var modelBuilder = new DbModelBuilder();
            modelBuilder.Entity<Foo2157>();
            modelBuilder.Entity<EnhancedFoo2157>().Map(m => m.Requires(o => o.XColumn).HasValue());

            var model1 = modelBuilder.Build(ProviderInfo);

            // making this change to force the actual diff
            modelBuilder.Entity<EnhancedFoo2157>().Property(e => e.Name).HasMaxLength(20);
            var model2 = modelBuilder.Build(ProviderInfo);

            var operations = new EdmModelDiffer().Diff(model1.GetModel(), model2.GetModel());
            var alterColumnOperation = (AlterColumnOperation)operations.Single();
            Assert.Equal("Name", alterColumnOperation.Column.Name);
        }
示例#10
0
        public void Can_detect_renamed_indexes()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity<IndexRename>();

            var model1 = modelBuilder.Build(ProviderInfo);

            modelBuilder
                .Entity<IndexRename>()
                .Property(p => p.Indexed)
                .HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("NewName")));

            var model2 = modelBuilder.Build(ProviderInfo);

            var operations
                = new EdmModelDiffer().Diff(model1.GetModel(), model2.GetModel());

            var renameIndexOperation = (RenameIndexOperation)operations.Single();

            Assert.Equal("dbo.IndexRenames", renameIndexOperation.Table);
            Assert.Equal("IX_Indexed", renameIndexOperation.Name);
            Assert.Equal("NewName", renameIndexOperation.NewName);
        }
示例#11
0
        public void Can_detect_removed_index()
        {
            var modelBuilder = new DbModelBuilder();
            modelBuilder.Entity<MigrationsCustomer>()
                .Property(c => c.CustomerNumber)
                .HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute("Bella")));

            var model1 = modelBuilder.Build(ProviderInfo);

            modelBuilder = new DbModelBuilder();
            modelBuilder.Entity<MigrationsCustomer>()
                .Property(c => c.CustomerNumber);

            var model2 = modelBuilder.Build(ProviderInfo);

            var operations = new EdmModelDiffer().Diff(model1.GetModel(), model2.GetModel());

            var dropIndexOperation = (DropIndexOperation)operations.Single();
            Assert.Equal("Bella", dropIndexOperation.Name);
            Assert.Equal("dbo.MigrationsCustomers", dropIndexOperation.Table);
            Assert.Equal(new List<string> { "CustomerNumber" }, dropIndexOperation.Columns);
        }
示例#12
0
        public void Can_detect_removed_column_annotations()
        {
            var modelBuilder = new DbModelBuilder();
            modelBuilder.Entity<MigrationsCustomer>()
                .Property(c => c.FullName)
                .HasColumnAnnotation("A1", "V1");

            var model1 = modelBuilder.Build(ProviderInfo);

            modelBuilder = new DbModelBuilder();
            modelBuilder.Entity<MigrationsCustomer>()
                .Property(c => c.FullName);

            var model2 = modelBuilder.Build(ProviderInfo);

            var operations = new EdmModelDiffer().Diff(model1.GetModel(), model2.GetModel());

            var alterColumnOperation = (AlterColumnOperation)operations.Single();

            Assert.Equal("V1", alterColumnOperation.Column.Annotations["A1"].OldValue);
            Assert.Null(alterColumnOperation.Column.Annotations["A1"].NewValue);
        }
示例#13
0
        public void Can_detect_changed_columns()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity<MigrationsCustomer>();

            var model1 = modelBuilder.Build(ProviderInfo);

            modelBuilder
                .Entity<MigrationsCustomer>()
                .Property(c => c.FullName)
                .HasMaxLength(25)
                .IsUnicode(false);

            var model2 = modelBuilder.Build(ProviderInfo);

            var operations 
                = new EdmModelDiffer().Diff(model1.GetModel(), model2.GetModel());

            var alterColumnOperation = (AlterColumnOperation)operations.Single();

            Assert.Equal(25, alterColumnOperation.Column.MaxLength);

            if (DatabaseProvider != DatabaseProvider.SqlServerCe)
            {
                Assert.Equal(false, alterColumnOperation.Column.IsUnicode);
            }

            var inverseAlterColumnOperation
                = (AlterColumnOperation)alterColumnOperation.Inverse;

            Assert.Equal("FullName", inverseAlterColumnOperation.Column.Name);

            Assert.Equal(
                DatabaseProvider != DatabaseProvider.SqlServerCe
                    ? (int?)null
                    : 4000,
                inverseAlterColumnOperation.Column.MaxLength);

            Assert.Null(inverseAlterColumnOperation.Column.IsUnicode);
        }
示例#14
0
        public void Can_detect_column_drop_when_ospace_type_renamed()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity<ColumnRename1>();

            var model1 = modelBuilder.Build(ProviderInfo);

            modelBuilder = new DbModelBuilder();

            modelBuilder.Entity<ColumnRename2>().Ignore(t => t.Member);

            var model2 = modelBuilder.Build(ProviderInfo);

            var operations
                = new EdmModelDiffer().Diff(model1.GetModel(), model2.GetModel());

            var dropColumnOperation = (DropColumnOperation)operations.Single();

            Assert.Equal("Member", dropColumnOperation.Name);
        }