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

DbContext: Owned entity types are incorrectly identified as tracked when clr types contain Equals implementation #8284

Closed
smitpatel opened this issue Apr 25, 2017 · 1 comment
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@smitpatel
Copy link
Member

While implementing #8283 , I added Equals method on entity types to make it easy to do comparison while verifying results. Doing so resulted in all of the tests in ComplexNavigationsOwnedQuerySqlServerTest failing with following error during seeding phase.

System.InvalidOperationException : The instance of entity type 'Level1.OneToOne_Required_PK->Level2.OneToOne_Required_PK->Level3.OneToOne_Required_PK->Level4' cannot be tracked because another instance with the key value 'Id:1' is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached.
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\IdentityMap.cs(206,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(TKey key, InternalEntityEntry entry)
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\IdentityMap.cs(191,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(InternalEntityEntry entry)
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\StateManager.cs(409,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTracking(InternalEntityEntry entry)
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\InternalEntityEntry.cs(195,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges)
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\InternalEntityEntry.cs(82,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges)
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\EntityGraphAttacher.cs(64,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintAction(EntityEntryGraphNode node)
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\EntityEntryGraphIterator.cs(25,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph(EntityEntryGraphNode node, Func`2 handleNode)
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\EntityEntryGraphIterator.cs(55,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph(EntityEntryGraphNode node, Func`2 handleNode)
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\EntityEntryGraphIterator.cs(55,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph(EntityEntryGraphNode node, Func`2 handleNode)
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\EntityGraphAttacher.cs(33,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.AttachGraph(InternalEntityEntry rootEntry, EntityState entityState)
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\NavigationFixer.cs(185,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.NavigationReferenceChanged(InternalEntityEntry entry, INavigation navigation, Object oldValue, Object newValue)
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\InternalEntityEntryNotifier.cs(135,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryNotifier.NavigationReferenceChanged(InternalEntityEntry entry, INavigation navigation, Object oldValue, Object newValue)
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\ChangeDetector.cs(210,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectNavigationChange(InternalEntityEntry entry, INavigation navigation)
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\ChangeDetector.cs(143,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(InternalEntityEntry entry)
	D:\EntityFramework\src\EFCore\ChangeTracking\Internal\ChangeDetector.cs(112,0): at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(IStateManager stateManager)
	D:\EntityFramework\src\EFCore\ChangeTracking\ChangeTracker.cs(162,0): at Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.DetectChanges()
	D:\EntityFramework\src\EFCore\DbContext.cs(320,0): at Microsoft.EntityFrameworkCore.DbContext.TryDetectChanges()
	D:\EntityFramework\src\EFCore\DbContext.cs(298,0): at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
	D:\EntityFramework\src\EFCore\DbContext.cs(276,0): at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
	D:\EntityFramework\src\EFCore.Specification.Tests\TestModels\ComplexNavigationsModel\ComplexNavigationsModelInitializer.cs(22,0): at Microsoft.EntityFrameworkCore.Specification.Tests.TestModels.ComplexNavigationsModel.ComplexNavigationsModelInitializer.Seed(ComplexNavigationsContext context)
	D:\EntityFramework\test\EFCore.SqlServer.FunctionalTests\ComplexNavigationsOwnedQuerySqlServerFixture.cs(46,0): at Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests.ComplexNavigationsOwnedQuerySqlServerFixture.<CreateTestStore>b__7_0()
	D:\EntityFramework\test\EFCore.SqlServer.FunctionalTests\Utilities\SqlServerTestStore.cs(90,0): at Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests.Utilities.SqlServerTestStore.<>c__DisplayClass21_0.<CreateShared>b__0()
	D:\EntityFramework\src\EFCore.Specification.Tests\TestStore.cs(29,0): at Microsoft.EntityFrameworkCore.Specification.Tests.TestStore.CreateShared(String name, Action initializeDatabase)
	D:\EntityFramework\test\EFCore.SqlServer.FunctionalTests\Utilities\SqlServerTestStore.cs(85,0): at Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests.Utilities.SqlServerTestStore.CreateShared(Action initializeDatabase)
	D:\EntityFramework\test\EFCore.SqlServer.FunctionalTests\Utilities\SqlServerTestStore.cs(38,0): at Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests.Utilities.SqlServerTestStore.GetOrCreateShared(String name, Action initializeDatabase, Boolean cleanDatabase)
	D:\EntityFramework\test\EFCore.SqlServer.FunctionalTests\ComplexNavigationsOwnedQuerySqlServerFixture.cs(41,0): at Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests.ComplexNavigationsOwnedQuerySqlServerFixture.CreateTestStore()
	D:\EntityFramework\src\EFCore.Specification.Tests\ComplexNavigationsQueryTestBase.cs(32,0): at Microsoft.EntityFrameworkCore.Specification.Tests.ComplexNavigationsQueryTestBase`2..ctor(TFixture fixture)
	D:\EntityFramework\src\EFCore.Specification.Tests\ComplexNavigationsOwnedQueryTestBase.cs(15,0): at Microsoft.EntityFrameworkCore.Specification.Tests.ComplexNavigationsOwnedQueryTestBase`2..ctor(TFixture fixture)
	D:\EntityFramework\test\EFCore.SqlServer.FunctionalTests\ComplexNavigationsOwnedQuerySqlServerTest.cs(17,0): at Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests.ComplexNavigationsOwnedQuerySqlServerTest..ctor(ComplexNavigationsOwnedQuerySqlServerFixture fixture, ITestOutputHelper testOutputHelper)
@smitpatel
Copy link
Member Author

@AndriySvyryd - Fixing this in same PR.

@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Apr 26, 2017
@smitpatel smitpatel added this to the 2.0.0-preview1 milestone Apr 26, 2017
@smitpatel smitpatel changed the title Re-enable owned entity types query tests Owned entity types are incorrectly identified as tracked when clr types contain Equals implementation Apr 26, 2017
@ajcvickers ajcvickers changed the title Owned entity types are incorrectly identified as tracked when clr types contain Equals implementation DbContext: Owned entity types are incorrectly identified as tracked when clr types contain Equals implementation May 9, 2017
@divega divega added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels May 10, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

4 participants