private void MapNestedFields(StoredFieldInfo oldField, StoredFieldInfo newField) { var oldNestedFields = ((IEnumerable <StoredFieldInfo>)oldField.Fields).ToArray(); if (oldNestedFields.Length == 0) { return; } var oldValueType = extractedModel.Types .Single(type => type.UnderlyingType == oldField.ValueType); foreach (var oldNestedField in oldNestedFields) { var oldNestedFieldOriginalName = oldNestedField.OriginalName; var oldNestedFieldOrigin = oldValueType.AllFields .Single(field => field.Name == oldNestedFieldOriginalName); if (!fieldMapping.ContainsKey(oldNestedFieldOrigin)) { continue; } var newNestedFieldOrigin = fieldMapping[oldNestedFieldOrigin]; var newNestedField = newField.Fields .Single(field => field.OriginalName == newNestedFieldOrigin.Name); MapFieldRecursively(oldNestedField, newNestedField); } }
private void MapNestedFields(StoredFieldInfo oldField, StoredFieldInfo newField) { var oldNestedFields = oldField.Fields; if (oldNestedFields.Length == 0) { return; } var oldValueType = extractedModel.Types .Single(type => type.UnderlyingType.Equals(oldField.ValueType, StringComparison.Ordinal)); foreach (var oldNestedField in oldNestedFields) { var oldNestedFieldOriginalName = oldNestedField.OriginalName; var oldNestedFieldOrigin = oldValueType.AllFields .Single(field => field.Name.Equals(oldNestedField.OriginalName, StringComparison.Ordinal)); if (fieldMapping.TryGetValue(oldNestedFieldOrigin, out var newNestedFieldOrigin)) { var newNestedField = newField.Fields .Single(field => field.OriginalName.Equals(newNestedFieldOrigin.Name, StringComparison.Ordinal)); MapFieldRecursively(oldNestedField, newNestedField); } } }
private static InvalidOperationException FieldsDoNotMatch(StoredFieldInfo fieldOne, StoredFieldInfo fieldTwo) { var nameOne = fieldOne.DeclaringType.UnderlyingType + "." + fieldOne.Name; var nameTwo = fieldTwo.DeclaringType.UnderlyingType + "." + fieldTwo.Name; return(new InvalidOperationException(string.Format( Strings.ExStructureOfFieldXDoesNotMatchStructureOfFieldY, nameOne, nameTwo))); }
private static bool CheckPropertyNameWasOverriden(StoredFieldInfo fieldInfo) { // if there is no real property then there is nothing to put OverrideFieldNameAttribute on if (string.IsNullOrEmpty(fieldInfo.PropertyName)) { return(false); } //seems to be it was OverrideFieldNameAttribute been applied; return(StringComparer.Ordinal.Compare(fieldInfo.PropertyName, fieldInfo.OriginalName) != 0); }
private void MapField(StoredFieldInfo oldField, StoredFieldInfo newField) { if (fieldMapping.TryGetValue(oldField, out var existingNewField)) { throw new InvalidOperationException(string.Format( Strings.ExUnableToAssociateFieldXWithFieldYFieldXIsAlreadyMappedToFieldZ, oldField, newField, existingNewField)); } fieldMapping[oldField] = newField; reverseFieldMapping[newField] = oldField; }
private void UpdateAffectedColumns(RemoveFieldHint hint) { if (hint.IsExplicit) { return; } var typeName = hint.Type; var storedType = extractedModel.Types .SingleOrDefault(type => type.UnderlyingType.Equals(typeName, StringComparison.Ordinal)); if (storedType == null) { throw TypeNotFound(typeName); } StoredFieldInfo storedField = null; // Nested field, looks like a field of a structure if (hint.Field.Contains(".", StringComparison.Ordinal)) { var path = hint.Field.Split('.'); var fields = storedType.AllFields; var fieldName = string.Empty; for (var i = 0; i < path.Length; i++) { fieldName += string.IsNullOrEmpty(fieldName) ? path[i] : "." + path[i]; var parameter = fieldName; storedField = fields.SingleOrDefault(field => field.Name.Equals(parameter, StringComparison.Ordinal)); if (storedField == null) { throw FieldNotFound(typeName, hint.Field); } fields = storedField.Fields; } } else { storedField = storedType.AllFields .SingleOrDefault(field => field.Name.Equals(hint.Field, StringComparison.Ordinal)); } if (storedField == null) { throw FieldNotFound(typeName, hint.Field); } var affectedColumns = GetAffectedColumns(storedType, storedField); hint.AffectedColumns = new ReadOnlyList <string>(affectedColumns); }
private List <string> GetAffectedColumns(StoredTypeInfo type, StoredFieldInfo field) { var affectedColumns = new List <string>(); if (type.IsStructure) { var structureFields = extractedModel.Types .Where(t => t.IsEntity) .SelectMany(t => extractedModelFields[t].Where(f => f.IsStructure && f.ValueType == type.UnderlyingType)); foreach (var structureField in structureFields) { var nestedField = structureField.Fields.FirstOrDefault(f => f.OriginalName == field.Name); if (nestedField != null) { affectedColumns.AddRange(GetAffectedColumns(structureField.DeclaringType, nestedField)); } } return(affectedColumns); } foreach (var primitiveField in field.PrimitiveFields) { var inheritanceSchema = type.Hierarchy.InheritanceSchema; switch (inheritanceSchema) { case InheritanceSchema.ClassTable: affectedColumns.Add(GetColumnPath(primitiveField.DeclaringType, primitiveField.MappingName)); break; case InheritanceSchema.SingleTable: affectedColumns.Add(GetColumnPath(type.Hierarchy.Root, primitiveField.MappingName)); break; case InheritanceSchema.ConcreteTable: var columns = GetAffectedMappedTypes(type, true) .Select(t => GetColumnPath(t, primitiveField.MappingName)); affectedColumns.AddRange(columns); break; default: throw Exceptions.InternalError(String.Format(Strings.ExInheritanceSchemaIsInvalid, inheritanceSchema), UpgradeLog.Instance); } } return(affectedColumns); }
private void GenerateRenameFieldHint(StoredFieldInfo oldField, StoredFieldInfo newField, StoredTypeInfo newType, bool includeInheritors) { if (oldField.MappingName == newField.MappingName) { return; } foreach (var newTargetType in GetAffectedMappedTypes(newType, includeInheritors)) { StoredTypeInfo oldTargetType; if (!reverseTypeMapping.TryGetValue(newTargetType, out oldTargetType)) { continue; } RegisterRenameFieldHint(oldTargetType, newTargetType, oldField.MappingName, newField.MappingName); } }
private bool IsRemoved(StoredFieldInfo field) { return(!fieldMapping.ContainsKey(field)); }
private void MapFieldRecursively(StoredFieldInfo oldField, StoredFieldInfo newField) { MapField(oldField, newField); MapNestedFields(oldField, newField); }