11// Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33
4- using System ;
54using System . Diagnostics . CodeAnalysis ;
65using Microsoft . EntityFrameworkCore . ChangeTracking . Internal ;
76using Microsoft . EntityFrameworkCore . Internal ;
@@ -28,6 +27,10 @@ public class Property : PropertyBase, IMutableProperty, IConventionProperty, IPr
2827 private ConfigurationSource ? _valueGeneratedConfigurationSource ;
2928 private ConfigurationSource ? _typeMappingConfigurationSource ;
3029
30+ private static readonly bool QuirkEnabled29642
31+ = AppContext . TryGetSwitch ( "Microsoft.EntityFrameworkCore.Issue29642" , out var enabled ) && enabled ;
32+
33+
3134 /// <summary>
3235 /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
3336 /// the same compatibility standards as public APIs. It may be changed or removed without notice in
@@ -670,6 +673,7 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
670673 var property = this ;
671674 for ( var i = 0 ; i < 10000 ; i ++ )
672675 {
676+ var currentProperty = property ;
673677 foreach ( var foreignKey in property . GetContainingForeignKeys ( ) )
674678 {
675679 for ( var propertyIndex = 0 ; propertyIndex < foreignKey . Properties . Count ; propertyIndex ++ )
@@ -690,9 +694,17 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
690694 {
691695 return converter ;
692696 }
697+
698+ currentProperty = principalProperty ;
693699 }
694700 }
695701 }
702+
703+ if ( ! QuirkEnabled29642
704+ && currentProperty == property )
705+ {
706+ break ;
707+ }
696708 }
697709
698710 return null ;
@@ -749,6 +761,7 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
749761 var property = this ;
750762 for ( var i = 0 ; i < 10000 ; i ++ )
751763 {
764+ var currentProperty = property ;
752765 foreach ( var foreignKey in property . GetContainingForeignKeys ( ) )
753766 {
754767 for ( var propertyIndex = 0 ; propertyIndex < foreignKey . Properties . Count ; propertyIndex ++ )
@@ -769,9 +782,17 @@ public virtual PropertySaveBehavior GetAfterSaveBehavior()
769782 {
770783 return type ;
771784 }
785+
786+ currentProperty = principalProperty ;
772787 }
773788 }
774789 }
790+
791+ if ( ! QuirkEnabled29642
792+ && currentProperty == property )
793+ {
794+ break ;
795+ }
775796 }
776797
777798 return null ;
0 commit comments