Skip to content

Commit

Permalink
Add quirk mode for #35110
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriySvyryd committed Nov 27, 2024
1 parent c49151c commit a7ad95c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class ForeignKeyPropertyDiscoveryConvention :
IPropertyFieldChangedConvention,
IModelFinalizingConvention
{
private static readonly bool UseOldBehavior35110 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue35110", out var enabled) && enabled;

/// <summary>
/// Creates a new instance of <see cref="ForeignKeyPropertyDiscoveryConvention" />.
/// </summary>
Expand Down Expand Up @@ -81,7 +84,8 @@ private IConventionForeignKeyBuilder ProcessForeignKey(
IConventionContext context)
{
var shouldBeRequired = true;
if (!relationshipBuilder.Metadata.IsOwnership)
if (!relationshipBuilder.Metadata.IsOwnership
|| UseOldBehavior35110)
{
foreach (var property in relationshipBuilder.Metadata.Properties)
{
Expand Down
11 changes: 9 additions & 2 deletions src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal;
/// </summary>
public class InternalEntityTypeBuilder : InternalTypeBaseBuilder, IConventionEntityTypeBuilder
{
private static readonly bool UseOldBehavior35110 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue35110", out var enabled) && enabled;

/// <summary>
/// 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
Expand Down Expand Up @@ -3171,8 +3174,12 @@ public static InternalIndexBuilder DetachIndex(Index indexToDetach)
+ "Owned types should only have ownership or ownee navigations point at it");

relationship = relationship.IsOwnership(true, configurationSource)
?.HasNavigations(inverse, navigation, configurationSource)
?.IsRequired(true, configurationSource);
?.HasNavigations(inverse, navigation, configurationSource);

if (!UseOldBehavior35110)
{
relationship = relationship?.IsRequired(true, configurationSource);
}

relationship?.Metadata.UpdateConfigurationSource(configurationSource);
return relationship;
Expand Down

0 comments on commit a7ad95c

Please sign in to comment.