internal void Configure( DbDatabaseMapping databaseMapping, MappingFragment fragment, EntityType entityType, DbProviderManifest providerManifest) { EdmProperty edmProperty = fragment.Table.Properties.SingleOrDefault <EdmProperty>((Func <EdmProperty, bool>)(c => string.Equals(c.Name, this.Discriminator, StringComparison.Ordinal))); if (edmProperty != null && ValueConditionConfiguration.GetMappingFragmentsWithColumnAsDefaultDiscriminator(databaseMapping, fragment.Table, edmProperty).Any <MappingFragment>()) { edmProperty.Name = fragment.Table.Properties.Select <EdmProperty, string>((Func <EdmProperty, string>)(p => p.Name)).Uniquify(edmProperty.Name); edmProperty = (EdmProperty)null; } if (edmProperty == null) { edmProperty = new EdmProperty(this.Discriminator, providerManifest.GetStoreType(DatabaseMappingGenerator.DiscriminatorTypeUsage)) { Nullable = false }; TablePrimitiveOperations.AddColumn(fragment.Table, edmProperty); } if (ValueConditionConfiguration.AnyBaseTypeToTableWithoutColumnCondition(databaseMapping, entityType, fragment.Table, edmProperty)) { edmProperty.Nullable = true; } System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration configuration = edmProperty.GetConfiguration() as System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration; if (this.Value != null) { this.ConfigureColumnType(providerManifest, configuration, edmProperty); fragment.AddDiscriminatorCondition(edmProperty, this.Value); } else { if (string.IsNullOrWhiteSpace(edmProperty.TypeName)) { TypeUsage storeType = providerManifest.GetStoreType(DatabaseMappingGenerator.DiscriminatorTypeUsage); edmProperty.PrimitiveType = (PrimitiveType)storeType.EdmType; edmProperty.MaxLength = new int?(128); edmProperty.Nullable = false; } this.GetOrCreateConfiguration <System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration>().IsNullable = new bool?(true); fragment.AddNullabilityCondition(edmProperty, true); } if (this._configuration == null) { return; } string errorMessage; if (configuration != null && (configuration.OverridableConfigurationParts & OverridableConfigurationParts.OverridableInCSpace) != OverridableConfigurationParts.OverridableInCSpace && !configuration.IsCompatible(this._configuration, true, out errorMessage)) { throw Error.ConflictingColumnConfiguration((object)edmProperty, (object)fragment.Table, (object)errorMessage); } if (this._configuration.IsNullable.HasValue) { edmProperty.Nullable = this._configuration.IsNullable.Value; } this._configuration.Configure(edmProperty, fragment.Table, providerManifest, false, 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 Properties.Primitive.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 <Properties.Primitive.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); }