protected virtual void EnsureDistinctColumnNames([NotNull] IModel model) { foreach (var entityType in model.GetEntityTypes()) { var columns = new HashSet <string>(); foreach (var property in entityType.GetProperties()) { var name = _relationalExtensions.For(property).ColumnName; if (!columns.Add(name)) { ShowError(RelationalStrings.DuplicateColumnName(name, entityType.Name, property.Name)); } } } }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> protected virtual void EnsureSharedColumnsCompatibility([NotNull] IModel model) { var groupedEntityTypes = new Dictionary <string, List <IEntityType> >(); foreach (var entityType in model.GetEntityTypes()) { var annotations = RelationalExtensions.For(entityType); var tableName = annotations.Schema + "." + annotations.TableName; if (!groupedEntityTypes.ContainsKey(tableName)) { groupedEntityTypes[tableName] = new List <IEntityType>(); } groupedEntityTypes[tableName].Add(entityType); } foreach (var table in groupedEntityTypes.Keys) { var properties = groupedEntityTypes[table].SelectMany(et => et.GetDeclaredProperties()); var propertyTypeMappings = new Dictionary <string, IProperty>(); foreach (var property in properties) { var propertyAnnotations = RelationalExtensions.For(property); var columnName = propertyAnnotations.ColumnName; IProperty duplicateProperty; if (propertyTypeMappings.TryGetValue(columnName, out duplicateProperty)) { var previousAnnotations = RelationalExtensions.For(duplicateProperty); var currentTypeString = propertyAnnotations.ColumnType ?? TypeMapper.GetMapping(property).StoreType; var previousTypeString = previousAnnotations.ColumnType ?? TypeMapper.GetMapping(duplicateProperty).StoreType; if (!currentTypeString.Equals(previousTypeString, StringComparison.OrdinalIgnoreCase)) { ShowError(RelationalStrings.DuplicateColumnName( duplicateProperty.DeclaringEntityType.DisplayName(), duplicateProperty.Name, property.DeclaringEntityType.DisplayName(), property.Name, columnName, table, previousTypeString, currentTypeString)); } if (property.IsColumnNullable() != duplicateProperty.IsColumnNullable()) { ShowError(RelationalStrings.DuplicateColumnNameNullabilityMismatch( duplicateProperty.DeclaringEntityType.DisplayName(), duplicateProperty.Name, property.DeclaringEntityType.DisplayName(), property.Name, columnName, table)); } var currentComputedColumnSql = propertyAnnotations.ComputedColumnSql ?? ""; var previousComputedColumnSql = previousAnnotations.ComputedColumnSql ?? ""; if (!currentComputedColumnSql.Equals(previousComputedColumnSql, StringComparison.OrdinalIgnoreCase)) { ShowError(RelationalStrings.DuplicateColumnNameComputedSqlMismatch( duplicateProperty.DeclaringEntityType.DisplayName(), duplicateProperty.Name, property.DeclaringEntityType.DisplayName(), property.Name, columnName, table, previousComputedColumnSql, currentComputedColumnSql)); } var currentDefaultValue = propertyAnnotations.DefaultValue; var previousDefaultValue = previousAnnotations.DefaultValue; if (currentDefaultValue != previousDefaultValue) { ShowError(RelationalStrings.DuplicateColumnNameDefaultSqlMismatch( duplicateProperty.DeclaringEntityType.DisplayName(), duplicateProperty.Name, property.DeclaringEntityType.DisplayName(), property.Name, columnName, table, previousDefaultValue ?? "NULL", currentDefaultValue ?? "NULL")); } var currentDefaultValueSql = propertyAnnotations.DefaultValueSql ?? ""; var previousDefaultValueSql = previousAnnotations.DefaultValueSql ?? ""; if (!currentDefaultValueSql.Equals(previousDefaultValueSql, StringComparison.OrdinalIgnoreCase)) { ShowError(RelationalStrings.DuplicateColumnNameDefaultSqlMismatch( duplicateProperty.DeclaringEntityType.DisplayName(), duplicateProperty.Name, property.DeclaringEntityType.DisplayName(), property.Name, columnName, table, previousDefaultValueSql, currentDefaultValueSql)); } } else { propertyTypeMappings[columnName] = property; } } } }