diff --git a/src/EFCore/Metadata/Internal/Property.cs b/src/EFCore/Metadata/Internal/Property.cs index 2aea996974a..154fd3173ae 100644 --- a/src/EFCore/Metadata/Internal/Property.cs +++ b/src/EFCore/Metadata/Internal/Property.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; using System.Diagnostics.CodeAnalysis; using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; using Microsoft.EntityFrameworkCore.Internal; @@ -28,6 +27,10 @@ public class Property : PropertyBase, IMutableProperty, IConventionProperty, IPr private ConfigurationSource? _valueGeneratedConfigurationSource; private ConfigurationSource? _typeMappingConfigurationSource; + private static readonly bool QuirkEnabled29642 + = AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue29642", out var enabled) && enabled; + + /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in @@ -670,6 +673,7 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior() var property = this; for (var i = 0; i < 10000; i++) { + var currentProperty = property; foreach (var foreignKey in property.GetContainingForeignKeys()) { for (var propertyIndex = 0; propertyIndex < foreignKey.Properties.Count; propertyIndex++) @@ -690,9 +694,17 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior() { return converter; } + + currentProperty = principalProperty; } } } + + if (!QuirkEnabled29642 + && currentProperty == property) + { + break; + } } return null; @@ -749,6 +761,7 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior() var property = this; for (var i = 0; i < 10000; i++) { + var currentProperty = property; foreach (var foreignKey in property.GetContainingForeignKeys()) { for (var propertyIndex = 0; propertyIndex < foreignKey.Properties.Count; propertyIndex++) @@ -769,9 +782,17 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior() { return type; } + + currentProperty = principalProperty; } } } + + if (!QuirkEnabled29642 + && currentProperty == property) + { + break; + } } return null;