Skip to content

Commit

Permalink
Use the correct builder when attaching indexes on nested owned entity…
Browse files Browse the repository at this point in the history
… types

Fixes #26659
  • Loading branch information
AndriySvyryd committed Nov 17, 2021
1 parent 6fc3e17 commit 214ed94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/PropertiesSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public virtual void Attach(InternalEntityTypeBuilder entityTypeBuilder)
{
var originalEntityType = indexBuilder.Metadata.DeclaringEntityType;
var targetEntityTypeBuilder = originalEntityType.Name == entityTypeBuilder.Metadata.Name
|| (!originalEntityType.HasSharedClrType && originalEntityType.ClrType == entityTypeBuilder.Metadata.ClrType)
|| (!originalEntityType.IsInModel && originalEntityType.ClrType == entityTypeBuilder.Metadata.ClrType)
? entityTypeBuilder
: originalEntityType.Builder;
indexBuilder.Attach(targetEntityTypeBuilder);
Expand Down
5 changes: 4 additions & 1 deletion test/EFCore.Tests/ModelBuilding/OwnedTypesTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,10 @@ public virtual void Can_configure_chained_ownerships()
l => l.AnotherBookLabel, ab =>
{
ab.Ignore(l => l.Book);
ab.OwnsOne(l => l.SpecialBookLabel).Ignore(l => l.Book).Ignore(s => s.BookLabel);
ab.OwnsOne(l => l.SpecialBookLabel)
.Ignore(l => l.Book)
.Ignore(s => s.BookLabel)
.HasIndex(l => l.BookId);
});
bb.OwnsOne(
l => l.SpecialBookLabel, sb =>
Expand Down

0 comments on commit 214ed94

Please sign in to comment.