{"action":"opened","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/7049","repository_url":"https://api.github.com/repos/aspnet/EntityFramework","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/7049/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/7049/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/7049/events","html_url":"https://github.com/aspnet/EntityFramework/issues/7049","id":190238945,"number":7049,"title":"Exception says another instance has same key, but it doesn't","user":{"login":"HappyNomad","id":3721251,"avatar_url":"https://avatars.githubusercontent.com/u/3721251?v=3","gravatar_id":"","url":"https://api.github.com/users/HappyNomad","html_url":"https://github.com/HappyNomad","followers_url":"https://api.github.com/users/HappyNomad/followers","following_url":"https://api.github.com/users/HappyNomad/following{/other_user}","gists_url":"https://api.github.com/users/HappyNomad/gists{/gist_id}","starred_url":"https://api.github.com/users/HappyNomad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HappyNomad/subscriptions","organizations_url":"https://api.github.com/users/HappyNomad/orgs","repos_url":"https://api.github.com/users/HappyNomad/repos","events_url":"https://api.github.com/users/HappyNomad/events{/privacy}","received_events_url":"https://api.github.com/users/HappyNomad/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-18T05:26:05Z","updated_at":"2016-11-18T05:26:05Z","closed_at":null,"body":"The issue can be reproduced with this version:\r\n\r\n\t\"Microsoft.EntityFrameworkCore.SqlServer\": \"1.2.0-preview*\",\r\n\r\nand this context:\r\n\r\n\tpublic class BloggingContext : DbContext\r\n\t{\r\n\t\tpublic BloggingContext( DbContextOptions<BloggingContext> options )\r\n\t\t\t: base( options ) { }\r\n\r\n\t\tpublic DbSet<L> Ls { get; set; }\r\n\t\tpublic DbSet<AL> ALs { get; set; }\r\n\t}\r\n\r\nand this model:\r\n\r\n\tpublic class L\r\n\t{\r\n\t\tpublic int ID { get; set; }\r\n\t\tpublic IList<T> Ts { get; set; }\r\n\t}\r\n\r\n\tpublic class T : P\r\n\t{\r\n\t\tpublic Q D { get; set; }\r\n\t\tpublic P P { get; set; }\r\n\t\tpublic Q F { get; set; }\r\n\t}\r\n\r\n\tpublic class P : PBase { }\r\n\r\n\tpublic class Q : PBase { }\r\n\r\n\tpublic abstract class PBase\r\n\t{\r\n\t\tpublic int ID { get; set; }\r\n\t\tpublic string Stuff { get; set; }\r\n\t}\r\n\r\n\tpublic class AL\r\n\t{\r\n\t\tpublic int ID { get; set; }\r\n\t\tpublic PBase L { get; set; }\r\n\t}\r\n\r\nThe \"seeding\" code is:\r\n\r\n\tdataContext.Ls.Add(\r\n\t\tnew L {\r\n\t\t\tTs = new[] { new T { D = new Q(), F = new Q() } }\r\n\t\t}\r\n\t);\r\n\r\nThe exception is:\r\n\r\nSystem.InvalidOperationException was unhandled by user code\r\n  HResult=-2146233079\r\n  Message=The instance of entity type 'Q' cannot be tracked because another instance of this type with the same key is already being tracked. When adding new entities, for most key types a unique temporary key value will be created if no key is set (i.e. if the key property is assigned the default value for its type). If you are explicitly setting key values for new entities, ensure they do not collide with existing entities or temporary values generated for other new entities. When attaching existing entities, ensure that only one entity instance with a given key value is attached to the context.\r\n  Source=Microsoft.EntityFrameworkCore\r\n  StackTrace:\r\n       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(TKey key, InternalEntityEntry entry)\r\n       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(InternalEntityEntry entry)\r\n       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTracking(InternalEntityEntry entry)\r\n       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges)\r\n       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges)\r\n       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintAction(EntityEntryGraphNode node)\r\n       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph(EntityEntryGraphNode node, Func`2 handleNode)\r\n       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph(EntityEntryGraphNode node, Func`2 handleNode)\r\n       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph(EntityEntryGraphNode node, Func`2 handleNode)\r\n       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.AttachGraph(InternalEntityEntry rootEntry, EntityState entityState)\r\n       at Microsoft.EntityFrameworkCore.DbContext.SetEntityState(InternalEntityEntry entry, EntityState entityState)\r\n       at Microsoft.EntityFrameworkCore.DbContext.SetEntityState[TEntity](TEntity entity, EntityState entityState)\r\n       at Microsoft.EntityFrameworkCore.DbContext.Add[TEntity](TEntity entity)\r\n       at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.Add(TEntity entity)\r\n       at EFGetStarted.AspNetCore.NewDb.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, BloggingContext dataContext) in C:\\Users\\Adrian\\Development\\Examples\\ASP.NET Core\\EFGetStarted.AspNetCore.NewDb\\src\\EFGetStarted.AspNetCore.NewDb\\Startup.cs:line 61\r\n  InnerException: \r\n"}}
{"actor":{"display_login":"HappyNomad"}}