public void BuildRelationship_returns_null_for_clr_types_if_dependent_entity_type_ignored()
        {
            var modelBuilder          = new InternalModelBuilder(new Model(), null);
            var customerEntityBuilder = modelBuilder.Entity(typeof(Customer), ConfigurationSource.Explicit);

            customerEntityBuilder.Key(new[] { Customer.IdProperty, Customer.UniqueProperty }, ConfigurationSource.Explicit);
            modelBuilder.Ignore(typeof(Order), ConfigurationSource.Explicit);

            var relationshipBuilder = customerEntityBuilder.BuildRelationship(typeof(Customer), typeof(Order), null, null, /*oneToOne:*/ true, ConfigurationSource.Convention);

            Assert.Null(relationshipBuilder);
        }
        public void Ignoring_an_entity_type_does_not_remove_referencing_lower_source_entity_types()
        {
            var modelBuilder = new InternalModelBuilder(new Model(), null);

            modelBuilder
            .Entity(typeof(Customer), ConfigurationSource.Convention)
            .Key(new[] { Customer.IdProperty }, ConfigurationSource.Convention);
            modelBuilder
            .Entity(typeof(Product), ConfigurationSource.Explicit)
            .Key(new[] { Product.IdProperty }, ConfigurationSource.Convention);

            var orderEntityTypeBuilder = modelBuilder.Entity(typeof(Order), ConfigurationSource.Convention);

            orderEntityTypeBuilder.ForeignKey(typeof(Customer), new[] { Order.CustomerIdProperty }, ConfigurationSource.Convention);
            orderEntityTypeBuilder.ForeignKey(typeof(Product), new[] { Order.ProductIdProperty }, ConfigurationSource.Convention);

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

            Assert.Equal(new[] { typeof(Order), typeof(Product) }, modelBuilder.Metadata.EntityTypes.Select(et => et.Type));
            Assert.Equal(typeof(Product), orderEntityTypeBuilder.Metadata.ForeignKeys.Single().ReferencedEntityType.Type);
        }
        public void Property_added_by_name_is_shadow_even_if_matches_Clr_type()
        {
            var model         = new Model();
            var modelBuilder  = new InternalModelBuilder(model);
            var entityBuilder = modelBuilder.Entity(typeof(Customer), ConfigurationSource.Explicit);
            var builder       = entityBuilder.Property(Customer.NameProperty.Name, ConfigurationSource.Convention);
            var property      = builder.Metadata;

            Assert.Equal(typeof(string), property.ClrType);
            Assert.True(property.IsShadowProperty);
            Assert.Null(property.GetClrTypeConfigurationSource());
            Assert.Null(property.GetIsShadowPropertyConfigurationSource());
        }
        public void Cannot_set_required_to_false_if_nonnullable()
        {
            var modelBuilder  = new InternalModelBuilder(new Model());
            var entityBuilder = modelBuilder.Entity(typeof(Customer), ConfigurationSource.Convention);
            var builder       = entityBuilder.Property(nameof(Customer.Id), ConfigurationSource.Convention);

            builder.HasClrType(typeof(int), ConfigurationSource.Convention);

            Assert.False(builder.IsRequired(false, ConfigurationSource.DataAnnotation));

            Assert.Equal(CoreStrings.CannotBeNullable(nameof(Customer.Id), typeof(Customer).Name, typeof(int).Name),
                         Assert.Throws <InvalidOperationException>(() => builder.IsRequired(false, ConfigurationSource.Explicit)).Message);
        }
예제 #5
0
        public void Can_only_override_existing_Shadow_value_explicitly()
        {
            var modelBuilder  = new InternalModelBuilder(new Model(), null);
            var entityBuilder = modelBuilder.Entity(typeof(Customer), ConfigurationSource.Explicit);
            var builder       = entityBuilder.Property(Customer.NameProperty.PropertyType, Customer.NameProperty.Name, ConfigurationSource.Explicit);
            var metadata      = builder.Metadata;

            Assert.False(builder.Shadow(false, ConfigurationSource.DataAnnotation));

            Assert.True(metadata.IsShadowProperty);

            Assert.True(builder.Shadow(false, ConfigurationSource.Explicit));
            Assert.False(metadata.IsShadowProperty);
        }
예제 #6
0
        public void Can_only_override_existing_ClrType_value_explicitly()
        {
            var model = new Model();

            model.AddEntityType(typeof(Customer)).AddProperty(Customer.NameProperty);
            var modelBuilder  = new InternalModelBuilder(model, new ConventionSet());
            var entityBuilder = modelBuilder.Entity(typeof(Customer), ConfigurationSource.Explicit);
            var builder       = entityBuilder.Property(Customer.NameProperty.Name, ConfigurationSource.Convention);

            Assert.True(builder.ClrType(typeof(string), ConfigurationSource.DataAnnotation));
            Assert.False(builder.ClrType(typeof(int), ConfigurationSource.DataAnnotation));

            Assert.Equal(typeof(string), builder.Metadata.ClrType);

            Assert.True(builder.ClrType(typeof(int), ConfigurationSource.Explicit));
            Assert.Equal(typeof(int), builder.Metadata.ClrType);
        }