Skip to content

Commit

Permalink
Don't match explicit implementations for InversePropertyAttribute
Browse files Browse the repository at this point in the history
Fixes #27024
  • Loading branch information
AndriySvyryd authored Sep 2, 2022
1 parent 922a01d commit 75cee40
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ private void Process(
var entityType = entityTypeBuilder.Metadata;
var targetEntityType = targetEntityTypeBuilder.Metadata;
var targetClrType = targetEntityType.ClrType;
var navigationCandidates = Dependencies.MemberClassifier.GetNavigationCandidates(targetEntityType);
var inverseNavigationPropertyInfo = targetEntityType.GetRuntimeProperties().Values
.FirstOrDefault(p => string.Equals(p.GetSimpleMemberName(), attribute.Property, StringComparison.Ordinal))
.FirstOrDefault(p => string.Equals(p.GetSimpleMemberName(), attribute.Property, StringComparison.Ordinal)
&& navigationCandidates.ContainsKey(p))
?? targetEntityType.GetRuntimeProperties().Values
.FirstOrDefault(p => string.Equals(p.GetSimpleMemberName(), attribute.Property, StringComparison.OrdinalIgnoreCase));
.FirstOrDefault(p => string.Equals(p.GetSimpleMemberName(), attribute.Property, StringComparison.OrdinalIgnoreCase)
&& navigationCandidates.ContainsKey(p));

if (inverseNavigationPropertyInfo == null
|| !Dependencies.MemberClassifier.GetNavigationCandidates(targetEntityType)[inverseNavigationPropertyInfo]
.Type.IsAssignableFrom(entityType.ClrType))
|| !navigationCandidates[inverseNavigationPropertyInfo].Type.IsAssignableFrom(entityType.ClrType))
{
throw new InvalidOperationException(
CoreStrings.InvalidNavigationWithInverseProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,12 @@ private class Post
public ICollection<Blog> Blogs { get; set; }
}

private class Principal
private interface IPrincipal
{
MismatchedInverseProperty MismatchedInverseProperty { get; set; }
}

private class Principal : IPrincipal
{
public static readonly PropertyInfo DependentIdProperty = typeof(Principal).GetProperty("DependentId");

Expand All @@ -1139,6 +1144,8 @@ private class Principal

[InverseProperty("AnotherPrincipal")]
public MismatchedInverseProperty MismatchedInverseProperty { get; set; }

MismatchedInverseProperty IPrincipal.MismatchedInverseProperty { get; set; }
}

private class Dependent
Expand Down

0 comments on commit 75cee40

Please sign in to comment.