Пример #1
0
        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;
                }
            }
        }
Пример #2
0
        public void RemoveDuplicateTphColumns()
        {
            for (var i = 0; i < _columnMappings.Count - 1;)
            {
                var entityType = _columnMappings[i].PropertyPath[0].DeclaringType;
                var column     = _columnMappings[i].ColumnProperty;

                var     indexAfterLastDuplicate = i + 1;
                EdmType _;
                while (indexAfterLastDuplicate < _columnMappings.Count &&
                       column.Name == _columnMappings[indexAfterLastDuplicate].ColumnProperty.Name &&
                       entityType != _columnMappings[indexAfterLastDuplicate].PropertyPath[0].DeclaringType &&
                       TypeSemantics.TryGetCommonBaseType(
                           entityType, _columnMappings[indexAfterLastDuplicate].PropertyPath[0].DeclaringType, out _))
                {
                    indexAfterLastDuplicate++;
                }

                var columnConfig = column.GetConfiguration() as PrimitivePropertyConfiguration;

                for (var toChangeIndex = i + 1; toChangeIndex < indexAfterLastDuplicate; toChangeIndex++)
                {
                    var toFixup        = _columnMappings[toChangeIndex];
                    var toChangeConfig = toFixup.ColumnProperty.GetConfiguration() as PrimitivePropertyConfiguration;

                    string configError;
                    if (columnConfig == null ||
                        columnConfig.IsCompatible(toChangeConfig, inCSpace: false, errorMessage: out configError))
                    {
                        if (toChangeConfig != null)
                        {
                            if (columnConfig == null)
                            {
                                columnConfig = toChangeConfig;
                                column.SetConfiguration(columnConfig);
                            }
                            else
                            {
                                columnConfig.FillFrom(toChangeConfig, inCSpace: false);
                            }

                            columnConfig.Configure(column);
                        }
                    }
                    else
                    {
                        throw new MappingException(
                                  Strings.BadTphMappingToSharedColumn(
                                      string.Join(".", _columnMappings[i].PropertyPath.Select(p => p.Name)),
                                      entityType.Name,
                                      string.Join(".", toFixup.PropertyPath.Select(p => p.Name)),
                                      toFixup.PropertyPath[0].DeclaringType.Name,
                                      column.Name,
                                      column.DeclaringType.Name,
                                      configError));
                    }

                    if (toFixup.ColumnProperty.DeclaringType.HasMember(toFixup.ColumnProperty))
                    {
                        toFixup.ColumnProperty.DeclaringType.RemoveMember(toFixup.ColumnProperty);
                    }
                    toFixup.ColumnProperty = column;
                }

                i = indexAfterLastDuplicate;
            }
        }
Пример #3
0
        public void RemoveDuplicateTphColumns()
        {
            for (var i = 0; i < _columnMappings.Count - 1;)
            {
                var entityType = _columnMappings[i].PropertyPath[0].DeclaringType;
                var column     = _columnMappings[i].ColumnProperty;

                var     indexAfterLastDuplicate = i + 1;
                EdmType _;
                while (indexAfterLastDuplicate < _columnMappings.Count &&
                       column.Name == _columnMappings[indexAfterLastDuplicate].ColumnProperty.Name &&
                       entityType != _columnMappings[indexAfterLastDuplicate].PropertyPath[0].DeclaringType &&
                       TypeSemantics.TryGetCommonBaseType(
                           entityType, _columnMappings[indexAfterLastDuplicate].PropertyPath[0].DeclaringType, out _))
                {
                    indexAfterLastDuplicate++;
                }

                var columnConfig = column.GetConfiguration() as Properties.Primitive.PrimitivePropertyConfiguration;

                for (var toChangeIndex = i + 1; toChangeIndex < indexAfterLastDuplicate; toChangeIndex++)
                {
                    var toFixup        = _columnMappings[toChangeIndex];
                    var toChangeConfig = toFixup.ColumnProperty.GetConfiguration() as Properties.Primitive.PrimitivePropertyConfiguration;

                    string configError;
                    if (columnConfig == null ||
                        columnConfig.IsCompatible(toChangeConfig, inCSpace: false, errorMessage: out configError))
                    {
                        if (toChangeConfig != null)
                        {
                            toChangeConfig.Configure(column, _table, _storeModel.ProviderManifest);
                        }
                    }
                    else
                    {
                        throw new MappingException(
                                  Strings.BadTphMappingToSharedColumn(
                                      string.Join(".", _columnMappings[i].PropertyPath.Select(p => p.Name)),
                                      entityType.Name,
                                      string.Join(".", toFixup.PropertyPath.Select(p => p.Name)),
                                      toFixup.PropertyPath[0].DeclaringType.Name,
                                      column.Name,
                                      column.DeclaringType.Name,
                                      configError));
                    }

                    column.Nullable = true;

                    var associations = from a in _storeModel.AssociationTypes
                                       where a.Constraint != null
                                       let p = a.Constraint.ToProperties
                                               where p.Contains(column) || p.Contains(toFixup.ColumnProperty)
                                               select a;

                    foreach (var association in associations.ToArray())
                    {
                        _storeModel.RemoveAssociationType(association);
                    }

                    if (toFixup.ColumnProperty.DeclaringType.HasMember(toFixup.ColumnProperty))
                    {
                        toFixup.ColumnProperty.DeclaringType.RemoveMember(toFixup.ColumnProperty);
                    }
                    toFixup.ColumnProperty = column;
                }

                i = indexAfterLastDuplicate;
            }
        }