コード例 #1
0
        public void Ignoring_an_entity_type_does_not_remove_referencing_lower_source_entity_types()
        {
            var modelBuilder = CreateModelBuilder();
            modelBuilder
                .Entity(typeof(Customer), ConfigurationSource.Convention)
                .PrimaryKey(new[] { Customer.IdProperty }, ConfigurationSource.Convention);
            modelBuilder
                .Entity(typeof(Product), ConfigurationSource.Explicit)
                .PrimaryKey(new[] { Product.IdProperty }, ConfigurationSource.Convention);

            var orderEntityTypeBuilder = modelBuilder.Entity(typeof(Order), ConfigurationSource.Convention);
            orderEntityTypeBuilder.HasForeignKey(typeof(Product), new[] { Order.ProductIdProperty }, ConfigurationSource.Convention)
                .PrincipalToDependent("Order", ConfigurationSource.Convention);

            Assert.True(modelBuilder.Ignore(typeof(Customer), ConfigurationSource.DataAnnotation));

            modelBuilder = new ModelCleanupConvention().Apply(modelBuilder);
            Assert.Equal(new[] { typeof(Order), typeof(Product) }, modelBuilder.Metadata.GetEntityTypes().Select(et => et.ClrType));
            Assert.Equal(typeof(Product), orderEntityTypeBuilder.Metadata.GetForeignKeys().Single().PrincipalEntityType.ClrType);
        }
コード例 #2
0
        public void Ignoring_an_entity_type_removes_lower_source_orphaned_entity_types()
        {
            var modelBuilder = CreateModelBuilder();
            modelBuilder
                .Entity(typeof(Customer), ConfigurationSource.Convention)
                .PrimaryKey(new[] { Customer.IdProperty }, ConfigurationSource.Convention);
            modelBuilder
                .Entity(typeof(Product), ConfigurationSource.Convention)
                .PrimaryKey(new[] { Product.IdProperty }, ConfigurationSource.Convention);

            var orderEntityTypeBuilder = modelBuilder.Entity(typeof(Order), ConfigurationSource.Convention);
            orderEntityTypeBuilder.HasForeignKey(typeof(Customer), new[] { Order.CustomerIdProperty }, ConfigurationSource.Convention);
            orderEntityTypeBuilder.HasForeignKey(typeof(Product), new[] { Order.ProductIdProperty }, ConfigurationSource.Convention);

            Assert.True(modelBuilder.Ignore(typeof(Customer), ConfigurationSource.Explicit));

            modelBuilder = new ModelCleanupConvention().Apply(modelBuilder);
            Assert.Empty(modelBuilder.Metadata.GetEntityTypes());
        }