Skip to content

Commit a7ad95c

Browse files
committed
Add quirk mode for #35110
1 parent c49151c commit a7ad95c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/EFCore/Metadata/Conventions/ForeignKeyPropertyDiscoveryConvention.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public class ForeignKeyPropertyDiscoveryConvention :
5050
IPropertyFieldChangedConvention,
5151
IModelFinalizingConvention
5252
{
53+
private static readonly bool UseOldBehavior35110 =
54+
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue35110", out var enabled) && enabled;
55+
5356
/// <summary>
5457
/// Creates a new instance of <see cref="ForeignKeyPropertyDiscoveryConvention" />.
5558
/// </summary>
@@ -81,7 +84,8 @@ private IConventionForeignKeyBuilder ProcessForeignKey(
8184
IConventionContext context)
8285
{
8386
var shouldBeRequired = true;
84-
if (!relationshipBuilder.Metadata.IsOwnership)
87+
if (!relationshipBuilder.Metadata.IsOwnership
88+
|| UseOldBehavior35110)
8589
{
8690
foreach (var property in relationshipBuilder.Metadata.Properties)
8791
{

src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal;
1515
/// </summary>
1616
public class InternalEntityTypeBuilder : InternalTypeBaseBuilder, IConventionEntityTypeBuilder
1717
{
18+
private static readonly bool UseOldBehavior35110 =
19+
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue35110", out var enabled) && enabled;
20+
1821
/// <summary>
1922
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
2023
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
@@ -3171,8 +3174,12 @@ public static InternalIndexBuilder DetachIndex(Index indexToDetach)
31713174
+ "Owned types should only have ownership or ownee navigations point at it");
31723175

31733176
relationship = relationship.IsOwnership(true, configurationSource)
3174-
?.HasNavigations(inverse, navigation, configurationSource)
3175-
?.IsRequired(true, configurationSource);
3177+
?.HasNavigations(inverse, navigation, configurationSource);
3178+
3179+
if (!UseOldBehavior35110)
3180+
{
3181+
relationship = relationship?.IsRequired(true, configurationSource);
3182+
}
31763183

31773184
relationship?.Metadata.UpdateConfigurationSource(configurationSource);
31783185
return relationship;

0 commit comments

Comments
 (0)