-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent re-entrance into DetectChanges
Fixes #30122 Fixes #30135 EF7 contained some new calls to local `DetectChanges`. This resulted in re-entrance into `DetectChanges` for some types of graphs. This change prevents that.
- Loading branch information
1 parent
df61347
commit 837cde8
Showing
10 changed files
with
1,053 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
...FCore.InMemory.FunctionalTests/GraphUpdates/GraphUpdatesIdentityResolutionInMemoryTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore; | ||
|
||
public class GraphUpdatesIdentityResolutionInMemoryTest | ||
: GraphUpdatesInMemoryTestBase<GraphUpdatesIdentityResolutionInMemoryTest.InMemoryIdentityResolutionFixture> | ||
{ | ||
public GraphUpdatesIdentityResolutionInMemoryTest(InMemoryIdentityResolutionFixture fixture) | ||
: base(fixture) | ||
{ | ||
} | ||
|
||
[ConditionalFact] | ||
public void Can_attach_full_required_graph_of_duplicates() | ||
=> ExecuteWithStrategyInTransaction( | ||
context => | ||
{ | ||
var trackedRoot = LoadRequiredGraph(context); | ||
var entries = context.ChangeTracker.Entries().ToList(); | ||
|
||
context.Attach(QueryRequiredGraph(context).AsNoTracking().Single(IsTheRoot)); | ||
|
||
AssertEntries(entries, context.ChangeTracker.Entries().ToList()); | ||
AssertNavigations(trackedRoot); | ||
|
||
Assert.Equal(0, context.SaveChanges()); | ||
}); | ||
|
||
[ConditionalFact] | ||
public void Can_attach_full_optional_graph_of_duplicates() | ||
=> ExecuteWithStrategyInTransaction( | ||
context => | ||
{ | ||
var trackedRoot = LoadOptionalGraph(context); | ||
var entries = context.ChangeTracker.Entries().ToList(); | ||
|
||
context.Attach(QueryOptionalGraph(context).AsNoTracking().Single(IsTheRoot)); | ||
|
||
AssertEntries(entries, context.ChangeTracker.Entries().ToList()); | ||
AssertNavigations(trackedRoot); | ||
|
||
Assert.Equal(0, context.SaveChanges()); | ||
}); | ||
|
||
[ConditionalFact] | ||
public void Can_attach_full_required_non_PK_graph_of_duplicates() | ||
=> ExecuteWithStrategyInTransaction( | ||
context => | ||
{ | ||
var trackedRoot = LoadRequiredNonPkGraph(context); | ||
var entries = context.ChangeTracker.Entries().ToList(); | ||
|
||
context.Attach(QueryRequiredNonPkGraph(context).AsNoTracking().Single(IsTheRoot)); | ||
|
||
AssertEntries(entries, context.ChangeTracker.Entries().ToList()); | ||
AssertNavigations(trackedRoot); | ||
|
||
Assert.Equal(0, context.SaveChanges()); | ||
}); | ||
|
||
[ConditionalFact] | ||
public void Can_attach_full_required_AK_graph_of_duplicates() | ||
=> ExecuteWithStrategyInTransaction( | ||
context => | ||
{ | ||
var trackedRoot = LoadRequiredAkGraph(context); | ||
var entries = context.ChangeTracker.Entries().ToList(); | ||
|
||
context.Attach(QueryRequiredAkGraph(context).AsNoTracking().Single(IsTheRoot)); | ||
|
||
AssertEntries(entries, context.ChangeTracker.Entries().ToList()); | ||
AssertNavigations(trackedRoot); | ||
|
||
Assert.Equal(0, context.SaveChanges()); | ||
}); | ||
|
||
[ConditionalFact] | ||
public void Can_attach_full_optional_AK_graph_of_duplicates() | ||
=> ExecuteWithStrategyInTransaction( | ||
context => | ||
{ | ||
var trackedRoot = LoadOptionalAkGraph(context); | ||
var entries = context.ChangeTracker.Entries().ToList(); | ||
|
||
context.Attach(QueryOptionalAkGraph(context).AsNoTracking().Single(IsTheRoot)); | ||
|
||
AssertEntries(entries, context.ChangeTracker.Entries().ToList()); | ||
AssertNavigations(trackedRoot); | ||
|
||
Assert.Equal(0, context.SaveChanges()); | ||
}); | ||
|
||
[ConditionalFact] | ||
public void Can_attach_full_required_non_PK_AK_graph_of_duplicates() | ||
=> ExecuteWithStrategyInTransaction( | ||
context => | ||
{ | ||
var trackedRoot = LoadRequiredNonPkAkGraph(context); | ||
var entries = context.ChangeTracker.Entries().ToList(); | ||
|
||
context.Attach(QueryRequiredNonPkAkGraph(context).AsNoTracking().Single(IsTheRoot)); | ||
|
||
AssertEntries(entries, context.ChangeTracker.Entries().ToList()); | ||
AssertNavigations(trackedRoot); | ||
|
||
Assert.Equal(0, context.SaveChanges()); | ||
}); | ||
|
||
[ConditionalFact] | ||
public void Can_attach_full_required_one_to_many_graph_of_duplicates() | ||
=> ExecuteWithStrategyInTransaction( | ||
context => | ||
{ | ||
var trackedRoot = LoadOptionalOneToManyGraph(context); | ||
var entries = context.ChangeTracker.Entries().ToList(); | ||
|
||
context.Attach(QueryOptionalOneToManyGraph(context).AsNoTracking().Single(IsTheRoot)); | ||
|
||
AssertEntries(entries, context.ChangeTracker.Entries().ToList()); | ||
AssertNavigations(trackedRoot); | ||
|
||
Assert.Equal(0, context.SaveChanges()); | ||
}); | ||
|
||
[ConditionalFact] | ||
public void Can_attach_full_required_composite_graph_of_duplicates() | ||
=> ExecuteWithStrategyInTransaction( | ||
context => | ||
{ | ||
var trackedRoot = LoadRequiredCompositeGraph(context); | ||
var entries = context.ChangeTracker.Entries().ToList(); | ||
|
||
context.Attach(QueryRequiredCompositeGraph(context).AsNoTracking().Single(IsTheRoot)); | ||
|
||
AssertEntries(entries, context.ChangeTracker.Entries().ToList()); | ||
AssertNavigations(trackedRoot); | ||
|
||
Assert.Equal(0, context.SaveChanges()); | ||
}); | ||
|
||
public class InMemoryIdentityResolutionFixture : GraphUpdatesInMemoryFixtureBase | ||
{ | ||
protected override string StoreName | ||
=> "GraphUpdatesIdentityResolutionTest"; | ||
|
||
public override bool HasIdentityResolution | ||
=> true; | ||
|
||
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder) | ||
=> base.AddOptions(builder).AddInterceptors(new UpdatingIdentityResolutionInterceptor()); | ||
} | ||
} |
Oops, something went wrong.