You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem:
The upgrade process fails when removing a Key attribute without removing the field itself. The exception is thrown in UpgradeHintsProcessor while processing nested fields.
Error:
The inner loop for nested fields is returning an error on Single because the SecondaryId field existed in the fieldMapping, but not in the nested fields of the self referencing MergedTo field where the SecondaryId was already removed.
Proposed solution:
Before checking if we need to map recursively, I think we should perform a null check to see if the nested field still exists by changing Single to SingleOrDefault.
var newNestedField = newField.Fields
.Single(field => field.OriginalName.Equals(newNestedFieldOrigin.Name, StringComparison.Ordinal));
Before state: Model with two key fields and a self referencing field that tracks both keys.
[HierarchyRoot(InheritanceSchema.ConcreteTable)]
public sealed class MultiKeyEntity: Entity
{
[Field, Key(0)]
public long Id { get; private set; }
[Field, Key(1)]
public long SecondaryId { get; private set; }
[Field(Nullable = true)]
public MultiKeyEntity? MergedTo { get; set; }
}
After state: Model with one key field (second field kept, but key attribute removed) and a self referencing field that tracks remaining key.
[HierarchyRoot(InheritanceSchema.ConcreteTable)]
public sealed class MultiKeyEntity: Entity
{
[Field, Key]
public long Id { get; private set; }
[Field]
public long SecondaryId { get; private set; }
[Field(Nullable = true)]
public MultiKeyEntity? MergedTo { get; set; }
}
Code block:
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);
}
}
}
The text was updated successfully, but these errors were encountered:
Problem:
The upgrade process fails when removing a Key attribute without removing the field itself. The exception is thrown in UpgradeHintsProcessor while processing nested fields.
Error:
The inner loop for nested fields is returning an error on
Single
because theSecondaryId
field existed in the fieldMapping, but not in the nested fields of the self referencingMergedTo
field where theSecondaryId
was already removed.Proposed solution:
Before checking if we need to map recursively, I think we should perform a null check to see if the nested field still exists by changing
Single
toSingleOrDefault
.Before state: Model with two key fields and a self referencing field that tracks both keys.
After state: Model with one key field (second field kept, but key attribute removed) and a self referencing field that tracks remaining key.
Code block:
The text was updated successfully, but these errors were encountered: