diff --git a/src/EFCore/Metadata/Internal/Property.cs b/src/EFCore/Metadata/Internal/Property.cs index 2aea996974a..7287b94bb63 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,9 @@ 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 +672,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++) @@ -693,6 +696,12 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior() } } } + + if (!QuirkEnabled29642 + && currentProperty == property) + { + break; + } } return null; @@ -749,6 +758,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++) @@ -772,6 +782,12 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior() } } } + + if (!QuirkEnabled29642 + && currentProperty == property) + { + break; + } } return null;