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), typeof(int), ConfigurationSource.Convention); Assert.False(builder.IsRequired(false, ConfigurationSource.DataAnnotation)); Assert.Equal( CoreStrings.CannotBeNullable(nameof(Customer.Id), typeof(Customer).Name, "int"), Assert.Throws <InvalidOperationException>(() => builder.IsRequired(false, ConfigurationSource.Explicit)).Message); }
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 Can_only_override_existing_ClrType_value_explicitly() { var model = new Model(); model.AddEntityType(typeof(Customer)).AddProperty(Customer.NameProperty.Name); var modelBuilder = new InternalModelBuilder(model); var entityBuilder = modelBuilder.Entity(typeof(Customer), ConfigurationSource.Explicit); var builder = entityBuilder.Property(Customer.NameProperty.Name, ConfigurationSource.Convention); Assert.Null(builder.Metadata.GetClrTypeConfigurationSource()); builder.Metadata.ClrType = typeof(string); Assert.Equal(ConfigurationSource.Explicit, builder.Metadata.GetClrTypeConfigurationSource()); Assert.True(builder.HasClrType(typeof(string), ConfigurationSource.DataAnnotation)); Assert.False(builder.HasClrType(typeof(int), ConfigurationSource.DataAnnotation)); Assert.Equal(typeof(string), builder.Metadata.ClrType); Assert.True(builder.HasClrType(typeof(int), ConfigurationSource.Explicit)); Assert.Equal(typeof(int), builder.Metadata.ClrType); }