private PrimitivePropertyConfiguration MergeWithExistingConfiguration( EdmProperty property, Func <string, Exception> getConflictException, bool inCSpace, bool fillFromExistingConfiguration) { var existingConfiguration = property.GetConfiguration() as PrimitivePropertyConfiguration; if (existingConfiguration != null) { var space = inCSpace ? OverridableConfigurationParts.OverridableInCSpace : OverridableConfigurationParts.OverridableInSSpace; if (existingConfiguration.OverridableConfigurationParts.HasFlag(space) || fillFromExistingConfiguration) { return(existingConfiguration.OverrideFrom(this, inCSpace)); } string errorMessage; if (OverridableConfigurationParts.HasFlag(space) || existingConfiguration.IsCompatible(this, inCSpace, errorMessage: out errorMessage)) { return(OverrideFrom(existingConfiguration, inCSpace)); } throw getConflictException(errorMessage); } return(this); }
private PrimitivePropertyConfiguration MergeWithExistingConfiguration( EdmProperty property, Func <string, Exception> getConflictException, bool inCSpace, bool fillFromExistingConfiguration) { PrimitivePropertyConfiguration configuration = property.GetConfiguration() as PrimitivePropertyConfiguration; if (configuration == null) { return(this); } OverridableConfigurationParts configurationParts = inCSpace ? OverridableConfigurationParts.OverridableInCSpace : OverridableConfigurationParts.OverridableInSSpace; if (configuration.OverridableConfigurationParts.HasFlag((Enum)configurationParts) || fillFromExistingConfiguration) { return(configuration.OverrideFrom(this, inCSpace)); } string errorMessage; if (this.OverridableConfigurationParts.HasFlag((Enum)configurationParts) || configuration.IsCompatible(this, inCSpace, out errorMessage)) { return(this.OverrideFrom(configuration, inCSpace)); } throw getConflictException(errorMessage); }
internal virtual void Configure( EdmProperty column, EntityType table, DbProviderManifest providerManifest, bool allowOverride = false, bool fillFromExistingConfiguration = false) { DebugCheck.NotNull(column); DebugCheck.NotNull(table); DebugCheck.NotNull(providerManifest); var existingConfiguration = column.GetConfiguration() as PrimitivePropertyConfiguration; if (existingConfiguration != null) { var overridable = column.GetAllowOverride(); string errorMessage; if ((existingConfiguration.OverridableConfigurationParts & OverridableConfigurationParts.OverridableInSSpace) != OverridableConfigurationParts.OverridableInSSpace && !overridable && !allowOverride && !fillFromExistingConfiguration && !existingConfiguration.IsCompatible(this, inCSpace: false, errorMessage: out errorMessage)) { throw Error.ConflictingColumnConfiguration(column.Name, table.Name, errorMessage); } FillFrom(existingConfiguration, inCSpace: false); } ConfigureColumnName(column, table); if (!string.IsNullOrWhiteSpace(ColumnType)) { column.PrimitiveType = providerManifest.GetStoreTypeFromName(ColumnType); } if (ColumnOrder != null) { column.SetOrder(ColumnOrder.Value); } var storeType = providerManifest.GetStoreTypes() .SingleOrDefault(t => t.Name.Equals(column.TypeName, StringComparison.OrdinalIgnoreCase)); if (storeType != null) { storeType.FacetDescriptions.Each(f => Configure(column, f)); } column.SetConfiguration(this); column.SetAllowOverride(allowOverride); }
public static void AddColumn(EntityType table, EdmProperty column) { DebugCheck.NotNull(table); DebugCheck.NotNull(column); if (!table.Properties.Contains(column)) { var configuration = column.GetConfiguration() as PrimitivePropertyConfiguration; if ((configuration == null) || string.IsNullOrWhiteSpace(configuration.ColumnName)) { var preferredName = column.GetPreferredName() ?? column.Name; column.SetUnpreferredUniqueName(column.Name); column.Name = table.Properties.UniquifyName(preferredName); } table.AddMember(column); } }
internal virtual void Configure(EdmProperty property) { DebugCheck.NotNull(property); Debug.Assert(property.TypeUsage != null); var existingConfiguration = property.GetConfiguration() as PrimitivePropertyConfiguration; if (existingConfiguration != null) { string errorMessage; if ((existingConfiguration.OverridableConfigurationParts & OverridableConfigurationParts.OverridableInCSpace) != OverridableConfigurationParts.OverridableInCSpace && !existingConfiguration.IsCompatible(this, inCSpace: true, errorMessage: out errorMessage)) { var propertyInfo = property.GetClrPropertyInfo(); var declaringTypeName = propertyInfo == null ? string.Empty : ObjectContextTypeCache.GetObjectType(propertyInfo.DeclaringType). FullNameWithNesting(); throw Error.ConflictingPropertyConfiguration(property.Name, declaringTypeName, errorMessage); } // Choose the more derived type for the merged configuration PrimitivePropertyConfiguration mergedConfiguration; if (existingConfiguration.GetType().IsAssignableFrom(GetType())) { mergedConfiguration = (PrimitivePropertyConfiguration)MemberwiseClone(); } else { mergedConfiguration = (PrimitivePropertyConfiguration)existingConfiguration.MemberwiseClone(); mergedConfiguration.CopyFrom(this); } mergedConfiguration.FillFrom(existingConfiguration, inCSpace: true); property.SetConfiguration(mergedConfiguration); } else { property.SetConfiguration(this); } if (IsNullable != null) { property.Nullable = IsNullable.Value; } if (ConcurrencyMode != null) { property.ConcurrencyMode = ConcurrencyMode.Value; } if (DatabaseGeneratedOption != null) { property.SetStoreGeneratedPattern((StoreGeneratedPattern)DatabaseGeneratedOption.Value); if (DatabaseGeneratedOption.Value == ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity) { property.Nullable = false; } } }
public void RemoveDuplicateTphColumns() { int index1; for (int index2 = 0; index2 < this._columnMappings.Count - 1; index2 = index1) { StructuralType declaringType = this._columnMappings[index2].PropertyPath[0].DeclaringType; EdmProperty column = this._columnMappings[index2].ColumnProperty; index1 = index2 + 1; EdmType commonBaseType; while (index1 < this._columnMappings.Count && column.Name == this._columnMappings[index1].ColumnProperty.Name && (declaringType != this._columnMappings[index1].PropertyPath[0].DeclaringType && TypeSemantics.TryGetCommonBaseType((EdmType)declaringType, (EdmType)this._columnMappings[index1].PropertyPath[0].DeclaringType, out commonBaseType))) { ++index1; } System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration configuration1 = column.GetConfiguration() as System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration; for (int index3 = index2 + 1; index3 < index1; ++index3) { ColumnMappingBuilder toFixup = this._columnMappings[index3]; System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration configuration2 = toFixup.ColumnProperty.GetConfiguration() as System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration; string errorMessage; if (configuration1 != null && !configuration1.IsCompatible(configuration2, false, out errorMessage)) { throw new MappingException(Strings.BadTphMappingToSharedColumn((object)string.Join(".", this._columnMappings[index2].PropertyPath.Select <EdmProperty, string>((Func <EdmProperty, string>)(p => p.Name))), (object)declaringType.Name, (object)string.Join(".", toFixup.PropertyPath.Select <EdmProperty, string>((Func <EdmProperty, string>)(p => p.Name))), (object)toFixup.PropertyPath[0].DeclaringType.Name, (object)column.Name, (object)column.DeclaringType.Name, (object)errorMessage)); } configuration2?.Configure(column, this._table, this._storeModel.ProviderManifest, false, false); column.Nullable = true; foreach (AssociationType associationType in this._storeModel.AssociationTypes.Where <AssociationType>((Func <AssociationType, bool>)(a => a.Constraint != null)).Select(a => new { a = a, p = a.Constraint.ToProperties }).Where(_param1 => { if (!_param1.p.Contains(column)) { return(_param1.p.Contains(toFixup.ColumnProperty)); } return(true); }).Select(_param0 => _param0.a).ToArray <AssociationType>()) { this._storeModel.RemoveAssociationType(associationType); } if (toFixup.ColumnProperty.DeclaringType.HasMember((EdmMember)toFixup.ColumnProperty)) { toFixup.ColumnProperty.DeclaringType.RemoveMember((EdmMember)toFixup.ColumnProperty); } toFixup.ColumnProperty = column; } } }
private static void ConfigureDependentKeys( DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest) { IList <EntityType> entityTypeList = databaseMapping.Database.EntityTypes as IList <EntityType> ?? (IList <EntityType>)databaseMapping.Database.EntityTypes.ToList <EntityType>(); for (int index1 = 0; index1 < entityTypeList.Count; ++index1) { EntityType entityType = entityTypeList[index1]; IList <ForeignKeyBuilder> foreignKeyBuilderList = entityType.ForeignKeyBuilders as IList <ForeignKeyBuilder> ?? (IList <ForeignKeyBuilder>)entityType.ForeignKeyBuilders.ToList <ForeignKeyBuilder>(); for (int index2 = 0; index2 < foreignKeyBuilderList.Count; ++index2) { ForeignKeyBuilder foreignKeyBuilder = foreignKeyBuilderList[index2]; IEnumerable <EdmProperty> dependentColumns = foreignKeyBuilder.DependentColumns; IList <EdmProperty> edmPropertyList = dependentColumns as IList <EdmProperty> ?? (IList <EdmProperty>)dependentColumns.ToList <EdmProperty>(); for (int index3 = 0; index3 < edmPropertyList.Count; ++index3) { EdmProperty edmProperty = edmPropertyList[index3]; System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration configuration = edmProperty.GetConfiguration() as System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration; if (configuration == null || configuration.ColumnType == null) { EdmProperty other = foreignKeyBuilder.PrincipalTable.KeyProperties.ElementAt <EdmProperty>(index3); edmProperty.PrimitiveType = providerManifest.GetStoreTypeFromName(other.TypeName); edmProperty.CopyFrom(other); } } } } }
public static void AddColumn(EntityType table, EdmProperty column) { if (table.Properties.Contains(column)) { return; } System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration configuration = column.GetConfiguration() as System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration; if (configuration == null || string.IsNullOrWhiteSpace(configuration.ColumnName)) { string name = column.GetPreferredName() ?? column.Name; column.SetUnpreferredUniqueName(column.Name); column.Name = ((IEnumerable <INamedDataModelItem>)table.Properties).UniquifyName(name); } table.AddMember((EdmMember)column); }