{"action":"closed","issue":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/10180","repository_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore","labels_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/10180/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/10180/comments","events_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/10180/events","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/10180","id":269437417,"number":10180,"title":"Unable to remove item by its PK only","user":{"login":"silarmani","id":33187297,"avatar_url":"https://avatars3.githubusercontent.com/u/33187297?v=4","gravatar_id":"","url":"https://api.github.com/users/silarmani","html_url":"https://github.com/silarmani","followers_url":"https://api.github.com/users/silarmani/followers","following_url":"https://api.github.com/users/silarmani/following{/other_user}","gists_url":"https://api.github.com/users/silarmani/gists{/gist_id}","starred_url":"https://api.github.com/users/silarmani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/silarmani/subscriptions","organizations_url":"https://api.github.com/users/silarmani/orgs","repos_url":"https://api.github.com/users/silarmani/repos","events_url":"https://api.github.com/users/silarmani/events{/privacy}","received_events_url":"https://api.github.com/users/silarmani/received_events","type":"User","site_admin":false},"labels":[{"id":816855155,"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/labels/punted-for-2.1","name":"punted-for-2.1","color":"fef2c0","default":false},{"id":76481852,"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/labels/type-bug","name":"type-bug","color":"f7c6c7","default":false}],"state":"closed","locked":false,"assignee":{"login":"AndriySvyryd","id":6539701,"avatar_url":"https://avatars0.githubusercontent.com/u/6539701?v=4","gravatar_id":"","url":"https://api.github.com/users/AndriySvyryd","html_url":"https://github.com/AndriySvyryd","followers_url":"https://api.github.com/users/AndriySvyryd/followers","following_url":"https://api.github.com/users/AndriySvyryd/following{/other_user}","gists_url":"https://api.github.com/users/AndriySvyryd/gists{/gist_id}","starred_url":"https://api.github.com/users/AndriySvyryd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndriySvyryd/subscriptions","organizations_url":"https://api.github.com/users/AndriySvyryd/orgs","repos_url":"https://api.github.com/users/AndriySvyryd/repos","events_url":"https://api.github.com/users/AndriySvyryd/events{/privacy}","received_events_url":"https://api.github.com/users/AndriySvyryd/received_events","type":"User","site_admin":false},"assignees":[{"login":"AndriySvyryd","id":6539701,"avatar_url":"https://avatars0.githubusercontent.com/u/6539701?v=4","gravatar_id":"","url":"https://api.github.com/users/AndriySvyryd","html_url":"https://github.com/AndriySvyryd","followers_url":"https://api.github.com/users/AndriySvyryd/followers","following_url":"https://api.github.com/users/AndriySvyryd/following{/other_user}","gists_url":"https://api.github.com/users/AndriySvyryd/gists{/gist_id}","starred_url":"https://api.github.com/users/AndriySvyryd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndriySvyryd/subscriptions","organizations_url":"https://api.github.com/users/AndriySvyryd/orgs","repos_url":"https://api.github.com/users/AndriySvyryd/repos","events_url":"https://api.github.com/users/AndriySvyryd/events{/privacy}","received_events_url":"https://api.github.com/users/AndriySvyryd/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/milestones/2","html_url":"https://github.com/aspnet/EntityFrameworkCore/milestone/2","labels_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/milestones/2/labels","id":648040,"number":2,"title":"Backlog","description":"Issues that have been approved but are not scheduled a specific release.","creator":{"login":"bricelam","id":1226749,"avatar_url":"https://avatars2.githubusercontent.com/u/1226749?v=4","gravatar_id":"","url":"https://api.github.com/users/bricelam","html_url":"https://github.com/bricelam","followers_url":"https://api.github.com/users/bricelam/followers","following_url":"https://api.github.com/users/bricelam/following{/other_user}","gists_url":"https://api.github.com/users/bricelam/gists{/gist_id}","starred_url":"https://api.github.com/users/bricelam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bricelam/subscriptions","organizations_url":"https://api.github.com/users/bricelam/orgs","repos_url":"https://api.github.com/users/bricelam/repos","events_url":"https://api.github.com/users/bricelam/events{/privacy}","received_events_url":"https://api.github.com/users/bricelam/received_events","type":"User","site_admin":false},"open_issues":585,"closed_issues":15,"state":"open","created_at":"2014-05-03T18:58:28Z","updated_at":"2018-04-23T21:40:09Z","due_on":null,"closed_at":null},"comments":6,"created_at":"2017-10-29T21:27:39Z","updated_at":"2018-04-23T21:40:09Z","closed_at":"2018-04-23T21:40:09Z","author_association":"NONE","body":"If an entity has extra indices then I am unable to delete it by its PK only\r\n\r\nExample\r\n\r\n```\r\n    class Program\r\n    {\r\n        static int Main(string[] args)\r\n        {\r\n            var ctx = new MyDbContext();\r\n\r\n            **var toBeDeleted = ctx.RiskConsequenceSeverityGroupItems\r\n                .Select(e => new RiskConsequenceSeverityGroupItem { Id = e.Id });**\r\n\r\n            ctx.RiskConsequenceSeverityGroupItems.RemoveRange(toBeDeleted);\r\n\r\n            ctx.SaveChanges();\r\n\r\n            return 0;\r\n        }\r\n    }\r\n\r\n    public class RiskConsequenceSeverityGroupItem\r\n    {\r\n        public int Id { get; set; }\r\n\r\n        public int Order { get; set; }\r\n\r\n        public string Name { get; set; }\r\n    }\r\n\r\n    public class MyDbContext : DbContext\r\n    {\r\n        public DbSet<RiskConsequenceSeverityGroupItem> RiskConsequenceSeverityGroupItems { get; set; }\r\n\r\n        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)\r\n        {\r\n            optionsBuilder.UseSqlServer(\"Server=localhost,1433;Database=ipl_tux;Integrated Security=True;\");            \r\n        }\r\n\r\n        protected override void OnModelCreating(ModelBuilder modelBuilder)\r\n        {\r\n            modelBuilder.Entity<RiskConsequenceSeverityGroupItem>()\r\n                .HasIndex(e => new { e.Order })\r\n                .IsUnique();\r\n\r\n            base.OnModelCreating(modelBuilder);\r\n        }\r\n    }\r\n```\r\n\r\nIn this case I get the following execption\r\n\r\nUnhandled Exception: System.ArgumentException: An item with the same key has already been added. Key: System.Object[]\r\n   at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException(Object key)\r\n   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)\r\n   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)\r\n   at Microsoft.EntityFrameworkCore.Update.Internal.CommandBatchPreparer.AddUniqueValueEdges(Multigraph`2 commandGraph)\r\n   at Microsoft.EntityFrameworkCore.Update.Internal.CommandBatchPreparer.TopologicalSort(IEnumerable`1 commands)\r\n   at Microsoft.EntityFrameworkCore.Update.Internal.CommandBatchPreparer.<BatchCommands>d__8.MoveNext()\r\n   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(Tuple`2 parameters)\r\n   at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)\r\n   at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func`2 operation)\r\n   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)\r\n   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IReadOnlyList`1 entries)\r\n   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)\r\n   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)\r\n   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)\r\n   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()\r\n   at EfTests.Program.Main(String[] args) in D:\\code\\tuxedo\\Tests\\EfBugTest.cs:line 17\r\n\r\nHowever, if I specify the extra column which has an index on then it works fine\r\n\r\nExample\r\n\r\n```\r\n            var toBeDeleted = ctx.RiskConsequenceSeverityGroupItems\r\n                .Select(e => new RiskConsequenceSeverityGroupItem { Id = e.Id**, Order = e.Order** });\r\n\r\n            ctx.RiskConsequenceSeverityGroupItems.RemoveRange(toBeDeleted);\r\n\r\n            ctx.SaveChanges();\r\n```\r\n\r\nHaving to specify that extra column seems to be irrelevant to me if all want to do is to delete it. It works even if I assign random numbers to it.\r\n\r\nExample\r\n\r\n```\r\n            var toBeDeleted = ctx.RiskConsequenceSeverityGroupItems\r\n                .Select(e => new RiskConsequenceSeverityGroupItem { Id = e.Id**, Order = new Random().Next()** });\r\n\r\n            ctx.RiskConsequenceSeverityGroupItems.RemoveRange(toBeDeleted);\r\n\r\n            ctx.SaveChanges();\r\n```\r\n"}}
{"actor":{"display_login":"ajcvickers"}}