internal void Configure( DbDatabaseMapping databaseMapping, MappingFragment fragment, EntityType entityType) { DebugCheck.NotNull(fragment); var edmPropertyPath = EntityMappingConfiguration.PropertyPathToEdmPropertyPath(PropertyPath, entityType); if (edmPropertyPath.Count() > 1) { throw Error.InvalidNotNullCondition(PropertyPath.ToString(), entityType.Name); } var column = fragment.ColumnMappings .Where(pm => pm.PropertyPath.SequenceEqual(edmPropertyPath.Single())) .Select(pm => pm.ColumnProperty) .SingleOrDefault(); if (column == null || !fragment.Table.Properties.Contains(column)) { throw Error.InvalidNotNullCondition(PropertyPath.ToString(), entityType.Name); } if (ValueConditionConfiguration.AnyBaseTypeToTableWithoutColumnCondition( databaseMapping, entityType, fragment.Table, column)) { column.Nullable = true; } // Make the property required var newConfiguration = new Properties.Primitive.PrimitivePropertyConfiguration { IsNullable = false, OverridableConfigurationParts = OverridableConfigurationParts.OverridableInSSpace }; newConfiguration.Configure(edmPropertyPath.Single().Last()); fragment.AddNullabilityCondition(column, isNull: false); }
public void Configure_should_preserve_the_most_derived_new_configuration() { var configurationA = CreateConfiguration(); configurationA.ConcurrencyMode = ConcurrencyMode.Fixed; var configurationB = new Properties.Primitive.PrimitivePropertyConfiguration(); configurationB.IsNullable = false; var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); Assert.Null(property.GetConfiguration()); configurationB.Configure(property); configurationA.Configure(property); Assert.Equal( ConcurrencyMode.Fixed, ((Properties.Primitive.PrimitivePropertyConfiguration)property.GetConfiguration()).ConcurrencyMode); Assert.Equal(false, ((Properties.Primitive.PrimitivePropertyConfiguration)property.GetConfiguration()).IsNullable); Assert.Equal(GetConfigurationType(), property.GetConfiguration().GetType()); }