@@ -14,6 +14,9 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal;
1414public class InternalPropertyBuilder
1515 : InternalPropertyBaseBuilder < IConventionPropertyBuilder , Property > , IConventionPropertyBuilder
1616{
17+ internal static readonly bool UseOldBehavior32430 =
18+ AppContext . TryGetSwitch ( "Microsoft.EntityFrameworkCore.Issue32430" , out var enabled32430 ) && enabled32430 ;
19+
1720 /// <summary>
1821 /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
1922 /// the same compatibility standards as public APIs. It may be changed or removed without notice in
@@ -496,7 +499,10 @@ public virtual bool CanSetValueGeneratorFactory(
496499 {
497500 if ( CanSetConversion ( converter , configurationSource ) )
498501 {
499- Metadata . SetElementType ( null , configurationSource ) ;
502+ if ( converter != null || UseOldBehavior32430 )
503+ {
504+ Metadata . SetElementType ( null , configurationSource ) ;
505+ }
500506 Metadata . SetProviderClrType ( null , configurationSource ) ;
501507 Metadata . SetValueConverter ( converter , configurationSource ) ;
502508
@@ -520,7 +526,8 @@ public virtual bool CanSetConversion(
520526 && Metadata . CheckValueConverter ( converter ) == null )
521527 || ( Metadata [ CoreAnnotationNames . ValueConverterType ] == null
522528 && ( ValueConverter ? ) Metadata [ CoreAnnotationNames . ValueConverter ] == converter ) )
523- && configurationSource . Overrides ( Metadata . GetProviderClrTypeConfigurationSource ( ) ) ;
529+ && configurationSource . Overrides ( Metadata . GetProviderClrTypeConfigurationSource ( ) )
530+ && ( converter == null || CanSetElementType ( null , configurationSource ) || UseOldBehavior32430 ) ;
524531
525532 /// <summary>
526533 /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -532,7 +539,10 @@ public virtual bool CanSetConversion(
532539 {
533540 if ( CanSetConversion ( providerClrType , configurationSource ) )
534541 {
535- Metadata . SetElementType ( null , configurationSource ) ;
542+ if ( providerClrType != null || UseOldBehavior32430 )
543+ {
544+ Metadata . SetElementType ( null , configurationSource ) ;
545+ }
536546 Metadata . SetValueConverter ( ( ValueConverter ? ) null , configurationSource ) ;
537547 Metadata . SetProviderClrType ( providerClrType , configurationSource ) ;
538548
@@ -551,7 +561,8 @@ public virtual bool CanSetConversion(
551561 public virtual bool CanSetConversion ( Type ? providerClrType , ConfigurationSource ? configurationSource )
552562 => ( configurationSource . Overrides ( Metadata . GetProviderClrTypeConfigurationSource ( ) )
553563 || Metadata . GetProviderClrType ( ) == providerClrType )
554- && configurationSource . Overrides ( Metadata . GetValueConverterConfigurationSource ( ) ) ;
564+ && configurationSource . Overrides ( Metadata . GetValueConverterConfigurationSource ( ) )
565+ && ( providerClrType == null || CanSetElementType ( null , configurationSource ) || UseOldBehavior32430 ) ;
555566
556567 /// <summary>
557568 /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -566,7 +577,10 @@ public virtual bool CanSetConversion(Type? providerClrType, ConfigurationSource?
566577 {
567578 if ( CanSetConverter ( converterType , configurationSource ) )
568579 {
569- Metadata . SetElementType ( null , configurationSource ) ;
580+ if ( converterType != null || UseOldBehavior32430 )
581+ {
582+ Metadata . SetElementType ( null , configurationSource ) ;
583+ }
570584 Metadata . SetProviderClrType ( null , configurationSource ) ;
571585 Metadata . SetValueConverter ( converterType , configurationSource ) ;
572586
@@ -586,9 +600,10 @@ public virtual bool CanSetConverter(
586600 [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicParameterlessConstructor ) ]
587601 Type ? converterType ,
588602 ConfigurationSource ? configurationSource )
589- => configurationSource . Overrides ( Metadata . GetValueConverterConfigurationSource ( ) )
603+ => ( configurationSource . Overrides ( Metadata . GetValueConverterConfigurationSource ( ) )
590604 || ( Metadata [ CoreAnnotationNames . ValueConverter ] == null
591- && ( Type ? ) Metadata [ CoreAnnotationNames . ValueConverterType ] == converterType ) ;
605+ && ( Type ? ) Metadata [ CoreAnnotationNames . ValueConverterType ] == converterType ) )
606+ && ( converterType == null || CanSetElementType ( null , configurationSource ) || UseOldBehavior32430 ) ;
592607
593608 /// <summary>
594609 /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -783,7 +798,10 @@ public virtual bool CanSetProviderValueComparer(
783798 if ( CanSetElementType ( elementType , configurationSource ) )
784799 {
785800 Metadata . SetElementType ( elementType , configurationSource ) ;
786- Metadata . SetValueConverter ( ( Type ? ) null , configurationSource ) ;
801+ if ( elementType != null || UseOldBehavior32430 )
802+ {
803+ Metadata . SetValueConverter ( ( Type ? ) null , configurationSource ) ;
804+ }
787805 return new InternalElementTypeBuilder ( Metadata . GetElementType ( ) ! , ModelBuilder ) ;
788806 }
789807
@@ -797,8 +815,9 @@ public virtual bool CanSetProviderValueComparer(
797815 /// doing so can result in application failures when updating to a new Entity Framework Core release.
798816 /// </summary>
799817 public virtual bool CanSetElementType ( Type ? elementType , ConfigurationSource ? configurationSource )
800- => configurationSource . Overrides ( Metadata . GetElementTypeConfigurationSource ( ) )
801- && ( elementType != Metadata . GetElementType ( ) ? . ClrType ) ;
818+ => ( configurationSource . Overrides ( Metadata . GetElementTypeConfigurationSource ( ) )
819+ && ( elementType == null || CanSetConversion ( ( Type ? ) null , configurationSource ) || UseOldBehavior32430 ) )
820+ || elementType == Metadata . GetElementType ( ) ? . ClrType ;
802821
803822 /// <summary>
804823 /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
0 commit comments