Skip to content

Commit

Permalink
Detect ambigous InversePropertyAttribute on collection navigations.
Browse files Browse the repository at this point in the history
Fixes #33327
  • Loading branch information
AndriySvyryd committed Mar 29, 2024
1 parent bfb5a6d commit 1d682ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ public static bool IsAmbiguous(
{
foreach (var (memberInfo, references) in navigationMap.Values)
{
if (memberInfo.GetMemberType().IsAssignableFrom(entityType.ClrType)
var memberInfoType = memberInfo.GetMemberType();
if ((memberInfoType.TryGetSequenceType() ?? memberInfoType).IsAssignableFrom(entityType.ClrType)
&& IsAmbiguousInverse(navigation, entityType, references))
{
return true;
Expand Down
23 changes: 23 additions & 0 deletions test/EFCore.Specification.Tests/DataAnnotationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2771,6 +2771,21 @@ public virtual void InverseProperty_with_case_sensitive_clr_property()
Validate(modelBuilder);
}

[ConditionalFact]
public virtual void InverseProperty_with_potentially_ambigous_derived_types()
{
var modelBuilder = CreateModelBuilder();
var model = modelBuilder.Model;

modelBuilder.Ignore<CPSorder>();
modelBuilder.Entity<SpecialOrder>();
modelBuilder.Entity<CPSpecialOrder>();

modelBuilder.Entity<CPSorder>().HasKey(e => e.Id);

Validate(modelBuilder);
}

public abstract class DataAnnotationFixtureBase : SharedStoreFixtureBase<PoolableDbContext>
{
protected override string StoreName
Expand Down Expand Up @@ -2929,4 +2944,12 @@ protected class Partner
[InverseProperty(nameof(CPSorder.CPSchargePartner))]
public virtual ICollection<CPSorder> CPSorders { get; set; }
}

protected class SpecialOrder : CPSorder
{
}

protected class CPSpecialOrder : CPSorder
{
}
}

0 comments on commit 1d682ca

Please sign in to comment.