internal void Configure( DbDatabaseMapping databaseMapping, StorageMappingFragment 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 PrimitivePropertyConfiguration { IsNullable = false, OverridableConfigurationParts = OverridableConfigurationParts.OverridableInSSpace }; newConfiguration.Configure(edmPropertyPath.Single().Last()); fragment.AddNullabilityCondition(column, isNull: false); }
internal void Configure( DbDatabaseMapping databaseMapping, StorageMappingFragment fragment, EntityType entityType, DbProviderManifest providerManifest) { DebugCheck.NotNull(fragment); DebugCheck.NotNull(providerManifest); var discriminatorColumn = fragment.Table.Properties .SingleOrDefault(c => string.Equals(c.Name, Discriminator, StringComparison.Ordinal)); if (discriminatorColumn == null) { var typeUsage = providerManifest.GetStoreType(DatabaseMappingGenerator.DiscriminatorTypeUsage); discriminatorColumn = new EdmProperty(Discriminator, typeUsage) { Nullable = false }; TablePrimitiveOperations.AddColumn(fragment.Table, discriminatorColumn); } if (AnyBaseTypeToTableWithoutColumnCondition( databaseMapping, entityType, fragment.Table, discriminatorColumn)) { discriminatorColumn.Nullable = true; } var existingConfiguration = discriminatorColumn.GetConfiguration() as PrimitivePropertyConfiguration; if (Value != null) { ConfigureColumnType(providerManifest, existingConfiguration, discriminatorColumn); fragment.AddDiscriminatorCondition(discriminatorColumn, Value); } else { if (string.IsNullOrWhiteSpace(discriminatorColumn.TypeName)) { var typeUsage = providerManifest.GetStoreType(DatabaseMappingGenerator.DiscriminatorTypeUsage); discriminatorColumn.PrimitiveType = (PrimitiveType)typeUsage.EdmType; discriminatorColumn.MaxLength = DatabaseMappingGenerator.DiscriminatorMaxLength; discriminatorColumn.Nullable = false; } GetOrCreateConfiguration <PrimitivePropertyConfiguration>().IsNullable = true; fragment.AddNullabilityCondition(discriminatorColumn, true); } if (_configuration == null) { return; } if (existingConfiguration != null) { string errorMessage; if ((existingConfiguration.OverridableConfigurationParts & OverridableConfigurationParts.OverridableInCSpace) != OverridableConfigurationParts.OverridableInCSpace && !existingConfiguration.IsCompatible( _configuration, inCSpace: true, errorMessage: out errorMessage)) { throw Error.ConflictingColumnConfiguration(discriminatorColumn, fragment.Table, errorMessage); } } if (_configuration.IsNullable != null) { discriminatorColumn.Nullable = _configuration.IsNullable.Value; } _configuration.Configure(discriminatorColumn, fragment.Table, providerManifest); }
internal void Configure( DbDatabaseMapping databaseMapping, StorageMappingFragment 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 PrimitivePropertyConfiguration { IsNullable = false, OverridableConfigurationParts = OverridableConfigurationParts.OverridableInSSpace }; newConfiguration.Configure(edmPropertyPath.Single().Last()); fragment.AddNullabilityCondition(column, isNull: false); }