Skip to content

Commit

Permalink
Make sure non-shared-type entity types aren't discovered while a shar…
Browse files Browse the repository at this point in the history
…ed-type entity type is being added

Fixes #22406
  • Loading branch information
AndriySvyryd committed Sep 5, 2020
1 parent 995919d commit 3c28237
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 178 deletions.
1 change: 1 addition & 0 deletions src/EFCore/Metadata/Internal/InternalModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private InternalEntityTypeBuilder Entity(
return null;
}

using var batch = Metadata.ConventionDispatcher.DelayConventions();
var clrType = type.Type;
EntityType entityType;
if (type.IsNamed)
Expand Down
6 changes: 3 additions & 3 deletions test/EFCore.Specification.Tests/ManyToManyTrackingTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,7 @@ static void ValidateFixup(
}
}

[ConditionalFact(Skip = "Issue #22406")]
[ConditionalFact]
public virtual void Can_insert_many_to_many_shared_with_payload()
{
ExecuteWithStrategyInTransaction(
Expand Down Expand Up @@ -1920,7 +1920,7 @@ void ValidateFixup(DbContext context, IList<EntityOne> leftEntities, IList<Entit
}
}

[ConditionalFact(Skip = "Issue #22406")]
[ConditionalFact]
public virtual void Can_update_many_to_many_shared_with_payload()
{
ExecuteWithStrategyInTransaction(
Expand Down Expand Up @@ -2990,7 +2990,7 @@ public virtual void Can_load_entities_in_any_order(int[] order)
Assert.Equal(112, (joinCount / 2) + deleted);
}

[ConditionalFact(Skip = "Issue #22406")]
[ConditionalFact]
public void Can_insert_update_delete_shared_type_entity_type()
{
ExecuteWithStrategyInTransaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
.UsingEntity<Dictionary<string, object>>(
"JoinOneToThreePayloadFullShared",
r => r.HasOne<EntityThree>().WithMany(e => e.JoinOnePayloadFullShared).HasForeignKey("ThreeId"),
l => l.HasOne<EntityOne>().WithMany(e => e.JoinThreePayloadFullShared).HasForeignKey("OneId"));
// Disabled - see #22406
//.IndexerProperty<string>("Payload");
l => l.HasOne<EntityOne>().WithMany(e => e.JoinThreePayloadFullShared).HasForeignKey("OneId"))
.IndexerProperty<string>("Payload");

// Nav:6 Payload:Yes Join:Concrete Extra:Self-Ref
modelBuilder.Entity<EntityOne>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
.Property(e => e.Payload)
.HasDefaultValueSql("GETUTCDATE()");

// Disabled - see #22406
// modelBuilder
// .SharedTypeEntity<Dictionary<string, object>>("JoinOneToThreePayloadFullShared")
// .IndexerProperty<string>("Payload")
// .HasDefaultValue("Generated");
modelBuilder
.SharedTypeEntity<Dictionary<string, object>>("JoinOneToThreePayloadFullShared")
.IndexerProperty<string>("Payload")
.HasDefaultValue("Generated");

modelBuilder
.Entity<JoinOneToThreePayloadFull>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
.Property(e => e.Payload)
.HasDefaultValueSql("GETUTCDATE()");

// Disabled - see #22406
// modelBuilder
// .SharedTypeEntity<Dictionary<string, object>>("JoinOneToThreePayloadFullShared")
// .IndexerProperty<string>("Payload")
// .HasDefaultValue("Generated");
modelBuilder
.SharedTypeEntity<Dictionary<string, object>>("JoinOneToThreePayloadFullShared")
.IndexerProperty<string>("Payload")
.HasDefaultValue("Generated");

modelBuilder
.Entity<JoinOneToThreePayloadFull>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,17 +659,16 @@ public override async Task Filtered_include_skip_navigation_where(bool async)
{
await base.Filtered_include_skip_navigation_where(async);

// Payload has been removed -- see #22406
// AssertSql(
// @"SELECT [e].[Id], [e].[CollectionInverseId], [e].[Name], [e].[ReferenceInverseId], [t].[OneId], [t].[ThreeId], [t].[Payload], [t].[Id], [t].[Name]
// FROM [EntityThrees] AS [e]
// LEFT JOIN (
// SELECT [j].[OneId], [j].[ThreeId], [j].[Payload], [e0].[Id], [e0].[Name]
// FROM [JoinOneToThreePayloadFullShared] AS [j]
// INNER JOIN [EntityOnes] AS [e0] ON [j].[OneId] = [e0].[Id]
// WHERE [e0].[Id] < 10
// ) AS [t] ON [e].[Id] = [t].[ThreeId]
// ORDER BY [e].[Id], [t].[OneId], [t].[ThreeId], [t].[Id]");
AssertSql(
@"SELECT [e].[Id], [e].[CollectionInverseId], [e].[Name], [e].[ReferenceInverseId], [t].[OneId], [t].[ThreeId], [t].[Payload], [t].[Id], [t].[Name]
FROM [EntityThrees] AS [e]
LEFT JOIN (
SELECT [j].[OneId], [j].[ThreeId], [j].[Payload], [e0].[Id], [e0].[Name]
FROM [JoinOneToThreePayloadFullShared] AS [j]
INNER JOIN [EntityOnes] AS [e0] ON [j].[OneId] = [e0].[Id]
WHERE [e0].[Id] < 10
) AS [t] ON [e].[Id] = [t].[ThreeId]
ORDER BY [e].[Id], [t].[OneId], [t].[ThreeId], [t].[Id]");
}

public override async Task Filtered_include_skip_navigation_order_by(bool async)
Expand Down Expand Up @@ -748,22 +747,21 @@ public override async Task Filtered_then_include_skip_navigation_where(bool asyn
{
await base.Filtered_then_include_skip_navigation_where(async);

// Payload has been removed -- see #22406
// AssertSql(
// @"SELECT [e].[Id], [e].[Discriminator], [e].[Name], [e].[Number], [e].[IsGreen], [t0].[EntityRootId], [t0].[EntityThreeId], [t0].[Id], [t0].[CollectionInverseId], [t0].[Name], [t0].[ReferenceInverseId], [t0].[OneId], [t0].[ThreeId], [t0].[Payload], [t0].[Id0], [t0].[Name0]
// FROM [EntityRoots] AS [e]
// LEFT JOIN (
// SELECT [e0].[EntityRootId], [e0].[EntityThreeId], [e1].[Id], [e1].[CollectionInverseId], [e1].[Name], [e1].[ReferenceInverseId], [t].[OneId], [t].[ThreeId], [t].[Payload], [t].[Id] AS [Id0], [t].[Name] AS [Name0]
// FROM [EntityRootEntityThree] AS [e0]
// INNER JOIN [EntityThrees] AS [e1] ON [e0].[EntityThreeId] = [e1].[Id]
// LEFT JOIN (
// SELECT [j].[OneId], [j].[ThreeId], [j].[Payload], [e2].[Id], [e2].[Name]
// FROM [JoinOneToThreePayloadFullShared] AS [j]
// INNER JOIN [EntityOnes] AS [e2] ON [j].[OneId] = [e2].[Id]
// WHERE [e2].[Id] < 10
// ) AS [t] ON [e1].[Id] = [t].[ThreeId]
// ) AS [t0] ON [e].[Id] = [t0].[EntityRootId]
// ORDER BY [e].[Id], [t0].[EntityRootId], [t0].[EntityThreeId], [t0].[Id], [t0].[OneId], [t0].[ThreeId], [t0].[Id0]");
AssertSql(
@"SELECT [e].[Id], [e].[Discriminator], [e].[Name], [e].[Number], [e].[IsGreen], [t0].[EntityRootId], [t0].[EntityThreeId], [t0].[Id], [t0].[CollectionInverseId], [t0].[Name], [t0].[ReferenceInverseId], [t0].[OneId], [t0].[ThreeId], [t0].[Payload], [t0].[Id0], [t0].[Name0]
FROM [EntityRoots] AS [e]
LEFT JOIN (
SELECT [e0].[EntityRootId], [e0].[EntityThreeId], [e1].[Id], [e1].[CollectionInverseId], [e1].[Name], [e1].[ReferenceInverseId], [t].[OneId], [t].[ThreeId], [t].[Payload], [t].[Id] AS [Id0], [t].[Name] AS [Name0]
FROM [EntityRootEntityThree] AS [e0]
INNER JOIN [EntityThrees] AS [e1] ON [e0].[EntityThreeId] = [e1].[Id]
LEFT JOIN (
SELECT [j].[OneId], [j].[ThreeId], [j].[Payload], [e2].[Id], [e2].[Name]
FROM [JoinOneToThreePayloadFullShared] AS [j]
INNER JOIN [EntityOnes] AS [e2] ON [j].[OneId] = [e2].[Id]
WHERE [e2].[Id] < 10
) AS [t] ON [e1].[Id] = [t].[ThreeId]
) AS [t0] ON [e].[Id] = [t0].[EntityRootId]
ORDER BY [e].[Id], [t0].[EntityRootId], [t0].[EntityThreeId], [t0].[Id], [t0].[OneId], [t0].[ThreeId], [t0].[Id0]");
}

public override async Task Filtered_then_include_skip_navigation_order_by_skip_take(bool async)
Expand Down Expand Up @@ -1113,21 +1111,20 @@ public override async Task Filtered_include_skip_navigation_where_split(bool asy
{
await base.Filtered_include_skip_navigation_where_split(async);

// Payload has been removed -- see #22406
// AssertSql(
// @"SELECT [e].[Id], [e].[CollectionInverseId], [e].[Name], [e].[ReferenceInverseId]
// FROM [EntityThrees] AS [e]
// ORDER BY [e].[Id]",
// //
// @"SELECT [t].[OneId], [t].[ThreeId], [t].[Payload], [t].[Id], [t].[Name], [e].[Id]
// FROM [EntityThrees] AS [e]
// INNER JOIN (
// SELECT [j].[OneId], [j].[ThreeId], [j].[Payload], [e0].[Id], [e0].[Name]
// FROM [JoinOneToThreePayloadFullShared] AS [j]
// INNER JOIN [EntityOnes] AS [e0] ON [j].[OneId] = [e0].[Id]
// WHERE [e0].[Id] < 10
// ) AS [t] ON [e].[Id] = [t].[ThreeId]
// ORDER BY [e].[Id]");
AssertSql(
@"SELECT [e].[Id], [e].[CollectionInverseId], [e].[Name], [e].[ReferenceInverseId]
FROM [EntityThrees] AS [e]
ORDER BY [e].[Id]",
//
@"SELECT [t].[OneId], [t].[ThreeId], [t].[Payload], [t].[Id], [t].[Name], [e].[Id]
FROM [EntityThrees] AS [e]
INNER JOIN (
SELECT [j].[OneId], [j].[ThreeId], [j].[Payload], [e0].[Id], [e0].[Name]
FROM [JoinOneToThreePayloadFullShared] AS [j]
INNER JOIN [EntityOnes] AS [e0] ON [j].[OneId] = [e0].[Id]
WHERE [e0].[Id] < 10
) AS [t] ON [e].[Id] = [t].[ThreeId]
ORDER BY [e].[Id]");
}

public override async Task Filtered_include_skip_navigation_order_by_split(bool async)
Expand Down Expand Up @@ -1226,35 +1223,34 @@ public override async Task Filtered_then_include_skip_navigation_where_split(boo
{
await base.Filtered_then_include_skip_navigation_where_split(async);

// Payload has been removed -- see #22406
// AssertSql(
// @"SELECT [e].[Id], [e].[Discriminator], [e].[Name], [e].[Number], [e].[IsGreen]
// FROM [EntityRoots] AS [e]
// ORDER BY [e].[Id]",
// //
// @"SELECT [t].[EntityRootId], [t].[EntityThreeId], [t].[Id], [t].[CollectionInverseId], [t].[Name], [t].[ReferenceInverseId], [e].[Id]
// FROM [EntityRoots] AS [e]
// INNER JOIN (
// SELECT [e0].[EntityRootId], [e0].[EntityThreeId], [e1].[Id], [e1].[CollectionInverseId], [e1].[Name], [e1].[ReferenceInverseId]
// FROM [EntityRootEntityThree] AS [e0]
// INNER JOIN [EntityThrees] AS [e1] ON [e0].[EntityThreeId] = [e1].[Id]
// ) AS [t] ON [e].[Id] = [t].[EntityRootId]
// ORDER BY [e].[Id], [t].[EntityRootId], [t].[EntityThreeId], [t].[Id]",
// //
// @"SELECT [t0].[OneId], [t0].[ThreeId], [t0].[Payload], [t0].[Id], [t0].[Name], [e].[Id], [t].[EntityRootId], [t].[EntityThreeId], [t].[Id]
// FROM [EntityRoots] AS [e]
// INNER JOIN (
// SELECT [e0].[EntityRootId], [e0].[EntityThreeId], [e1].[Id]
// FROM [EntityRootEntityThree] AS [e0]
// INNER JOIN [EntityThrees] AS [e1] ON [e0].[EntityThreeId] = [e1].[Id]
// ) AS [t] ON [e].[Id] = [t].[EntityRootId]
// INNER JOIN (
// SELECT [j].[OneId], [j].[ThreeId], [j].[Payload], [e2].[Id], [e2].[Name]
// FROM [JoinOneToThreePayloadFullShared] AS [j]
// INNER JOIN [EntityOnes] AS [e2] ON [j].[OneId] = [e2].[Id]
// WHERE [e2].[Id] < 10
// ) AS [t0] ON [t].[Id] = [t0].[ThreeId]
// ORDER BY [e].[Id], [t].[EntityRootId], [t].[EntityThreeId], [t].[Id]");
AssertSql(
@"SELECT [e].[Id], [e].[Discriminator], [e].[Name], [e].[Number], [e].[IsGreen]
FROM [EntityRoots] AS [e]
ORDER BY [e].[Id]",
//
@"SELECT [t].[EntityRootId], [t].[EntityThreeId], [t].[Id], [t].[CollectionInverseId], [t].[Name], [t].[ReferenceInverseId], [e].[Id]
FROM [EntityRoots] AS [e]
INNER JOIN (
SELECT [e0].[EntityRootId], [e0].[EntityThreeId], [e1].[Id], [e1].[CollectionInverseId], [e1].[Name], [e1].[ReferenceInverseId]
FROM [EntityRootEntityThree] AS [e0]
INNER JOIN [EntityThrees] AS [e1] ON [e0].[EntityThreeId] = [e1].[Id]
) AS [t] ON [e].[Id] = [t].[EntityRootId]
ORDER BY [e].[Id], [t].[EntityRootId], [t].[EntityThreeId], [t].[Id]",
//
@"SELECT [t0].[OneId], [t0].[ThreeId], [t0].[Payload], [t0].[Id], [t0].[Name], [e].[Id], [t].[EntityRootId], [t].[EntityThreeId], [t].[Id]
FROM [EntityRoots] AS [e]
INNER JOIN (
SELECT [e0].[EntityRootId], [e0].[EntityThreeId], [e1].[Id]
FROM [EntityRootEntityThree] AS [e0]
INNER JOIN [EntityThrees] AS [e1] ON [e0].[EntityThreeId] = [e1].[Id]
) AS [t] ON [e].[Id] = [t].[EntityRootId]
INNER JOIN (
SELECT [j].[OneId], [j].[ThreeId], [j].[Payload], [e2].[Id], [e2].[Name]
FROM [JoinOneToThreePayloadFullShared] AS [j]
INNER JOIN [EntityOnes] AS [e2] ON [j].[OneId] = [e2].[Id]
WHERE [e2].[Id] < 10
) AS [t0] ON [t].[Id] = [t0].[ThreeId]
ORDER BY [e].[Id], [t].[EntityRootId], [t].[EntityThreeId], [t].[Id]");
}

public override async Task Filtered_then_include_skip_navigation_order_by_skip_take_split(bool async)
Expand Down
Loading

0 comments on commit 3c28237

Please sign in to comment.