Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.0.1] Match indexer properties correctly #26645

Merged
merged 3 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/EFCore/Metadata/Internal/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,13 @@ 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()
&& (!AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26590", out var enabled) || !enabled)
? 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