Skip to content

Commit

Permalink
Match indexer properties correctly
Browse files Browse the repository at this point in the history
Fixes #26590
  • Loading branch information
AndriySvyryd committed Nov 12, 2021
1 parent cb6d523 commit 8b61f64
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/EFCore/Metadata/Internal/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,12 @@ public static bool AreCompatible(IReadOnlyList<Property> properties, EntityType
=> properties.All(
property =>
property.IsShadowProperty()
|| ((property.PropertyInfo != null
&& entityType.GetRuntimeProperties().ContainsKey(property.Name))
|| (property.FieldInfo != null
&& entityType.GetRuntimeFields().ContainsKey(property.Name))));
|| (property.IsIndexerProperty()
? property.PropertyInfo == entityType.FindIndexerPropertyInfo()
: ((property.PropertyInfo != null
&& entityType.GetRuntimeProperties().ContainsKey(property.Name))
|| (property.FieldInfo != null
&& entityType.GetRuntimeFields().ContainsKey(property.Name)))));

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
45 changes: 45 additions & 0 deletions test/EFCore.Specification.Tests/DataAnnotationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,51 @@ protected class Profile15
public virtual Profile15 Profile4 { get; set; }
}

[ConditionalFact]
public virtual void ForeignKey_to_ForeignKey_on_many_to_many()
{
var modelBuilder = CreateModelBuilder();

modelBuilder.Entity<Login16>(entity =>
{
entity.HasMany(d => d.Profile16s)
.WithMany(p => p.Login16s)
.UsingEntity<Dictionary<string, object>>(
"Login16Profile16",
l => l.HasOne<Profile16>().WithMany().HasForeignKey("Profile16Id"),
r => r.HasOne<Login16>().WithMany().HasForeignKey("Login16Id"),
j =>
{
j.HasKey("Login16Id", "Profile16Id");
j.ToTable("Login16Profile16");
});
});

var model = Validate(modelBuilder);

var login = modelBuilder.Model.FindEntityType(typeof(Login16));
var logins = login.FindSkipNavigation(nameof(Login16.Profile16s));
var join = logins.JoinEntityType;
Assert.Equal(2, join.GetProperties().Count());
Assert.False(GetProperty<Login16>(model, "Login16Id").IsForeignKey());
Assert.False(GetProperty<Profile16>(model, "Profile16Id").IsForeignKey());
}

public partial class Login16
{
public int Login16Id { get; set; }
[ForeignKey("Login16Id")]
public virtual ICollection<Profile16> Profile16s { get; set; }
}

public partial class Profile16
{
public int Profile16Id { get; set; }
[ForeignKey("Profile16Id")]
public virtual ICollection<Login16> Login16s { get; set; }
}

[ConditionalFact]
public virtual void ForeignKeyAttribute_configures_relationships_when_inverse_on_derived()
{
Expand Down

0 comments on commit 8b61f64

Please sign in to comment.