{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1373","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1373/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1373/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1373/events","html_url":"https://github.com/aspnet/EntityFramework/issues/1373","id":53815117,"number":1373,"title":"Conventions :: model is configured differently based on the name of Primary Keys","user":{"login":"maumar","id":1591930,"avatar_url":"https://avatars.githubusercontent.com/u/1591930?v=3","gravatar_id":"","url":"https://api.github.com/users/maumar","html_url":"https://github.com/maumar","followers_url":"https://api.github.com/users/maumar/followers","following_url":"https://api.github.com/users/maumar/following{/other_user}","gists_url":"https://api.github.com/users/maumar/gists{/gist_id}","starred_url":"https://api.github.com/users/maumar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maumar/subscriptions","organizations_url":"https://api.github.com/users/maumar/orgs","repos_url":"https://api.github.com/users/maumar/repos","events_url":"https://api.github.com/users/maumar/events{/privacy}","received_events_url":"https://api.github.com/users/maumar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-08T23:26:23Z","updated_at":"2015-01-08T23:28:24Z","closed_at":null,"body":"Consider the following model:\r\n\r\n```\r\n    public class Customer\r\n    {\r\n        public int CId { get; set; }\r\n        public string Name { get; set; }\r\n\r\n        public Order Order { get; set; }\r\n    }\r\n\r\n    public class Order\r\n    {\r\n        public int OId { get; set; }\r\n        public string Name { get; set; }\r\n    }\r\n\r\n    public class MyContext : DbContext\r\n    {\r\n        public DbSet<Customer> Customers { get; set; }\r\n        public DbSet<Order> Orders { get; set; }\r\n\r\n        protected override void OnModelCreating(ModelBuilder modelBuilder)\r\n        {\r\n            modelBuilder.Entity<Customer>().Key(o => o.CId);\r\n            modelBuilder.Entity<Order>().Key(o => o.OId);\r\n            modelBuilder.Entity<Customer>().OneToOne(c => c.Order);\r\n            modelBuilder.Entity<Order>().Key(o => o.OId);\r\n        }\r\n\r\n        protected override void OnConfiguring(DbContextOptions options)\r\n        {\r\n            options.UseSqlServer(new SqlConnectionStringBuilder { DataSource = \".\", InitialCatalog = \"MultiLevelInclude2\", MultipleActiveResultSets = true, IntegratedSecurity = true }.ToString());\r\n        }\r\n    }\r\n\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            using (var ctx = new MyContext())\r\n            {\r\n                ctx.Database.EnsureDeleted();\r\n                ctx.Database.EnsureCreated();\r\n\r\n                var c1 = new Customer\r\n                {\r\n                    CId = 1,\r\n                    Name = \"Customer1\"\r\n                };\r\n\r\n                var o1 = new Order\r\n                {\r\n                    OId = 1,\r\n                    Name = \"Order1\"\r\n                };\r\n\r\n                ctx.Customers.Add(c1);\r\n                ctx.Orders.Add(o1);\r\n\r\n                ctx.SaveChanges();\r\n\r\n                c1.Order = o1;\r\n\r\n                ctx.SaveChanges();\r\n            }\r\n        }\r\n    }\r\n```\r\n\r\nthis works fine, however if the PKs on Customer and Order would be refactor-renamed into \"Id\", we start throwing exception:\r\n\r\nUnhandled Exception: Microsoft.Data.Entity.Update.DbUpdateException: An error oc\r\ncurred while updating the entries. See the inner exception for details. ---> Sys\r\ntem.Data.SqlClient.SqlException: Cannot insert explicit value for identity colum\r\nn in table 'Customer' when IDENTITY_INSERT is set to OFF.\r\n   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolea\r\nn breakConnection, Action`1 wrapCloseInAction)\r\n   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception\r\n, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObj\r\nect stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)\r\n   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand\r\n cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,\r\nTdsParserStateObject stateObj, Boolean& dataReady)\r\n   at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()\r\n   at System.Data.SqlClient.SqlDataReader.get_MetaData()\r\n   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, Run\r\nBehavior runBehavior, String resetOptionsString)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBe\r\nhavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 time\r\nout, Task& task, Boolean asyncWrite, SqlDataReader ds)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehav\r\nior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletio\r\nnSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehav\r\nior, RunBehavior runBehavior, Boolean returnStream, String method)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, S\r\ntring method)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behav\r\nior)\r\n   at System.Data.Common.DbCommand.ExecuteReader()\r\n   at Microsoft.Data.Entity.Relational.Update.ReaderModificationCommandBatch.Exe\r\ncute(RelationalTransaction transaction, RelationalTypeMapper typeMapper, DbConte\r\nxt context, ILogger logger) in D:\\k\\EntityFramework\\src\\EntityFramework.Relation\r\nal\\Update\\ReaderModificationCommandBatch.cs:line 168\r\n   --- End of inner exception stack trace ---\r\n   at Microsoft.Data.Entity.Relational.Update.ReaderModificationCommandBatch.Exe\r\ncute(RelationalTransaction transaction, RelationalTypeMapper typeMapper, DbConte\r\nxt context, ILogger logger) in D:\\k\\EntityFramework\\src\\EntityFramework.Relation\r\nal\\Update\\ReaderModificationCommandBatch.cs:line 196\r\n   at Microsoft.Data.Entity.Relational.Update.BatchExecutor.Execute(IEnumerable`\r\n1 commandBatches, RelationalConnection connection) in D:\\k\\EntityFramework\\src\\E\r\nntityFramework.Relational\\Update\\BatchExecutor.cs:line 68\r\n   at Microsoft.Data.Entity.Relational.RelationalDataStore.SaveChanges(IReadOnly\r\nList`1 stateEntries) in D:\\k\\EntityFramework\\src\\EntityFramework.Relational\\Rela\r\ntionalDataStore.cs:line 76\r\n   at Microsoft.Data.Entity.ChangeTracking.StateManager.SaveChanges(IReadOnlyLis\r\nt`1 entriesToSave) in D:\\k\\EntityFramework\\src\\EntityFramework.Core\\ChangeTracki\r\nng\\StateManager.cs:line 415\r\n   at Microsoft.Data.Entity.ChangeTracking.StateManager.SaveChanges() in D:\\k\\En\r\ntityFramework\\src\\EntityFramework.Core\\ChangeTracking\\StateManager.cs:line 368\r\n   at Microsoft.Data.Entity.DbContext.SaveChanges() in D:\\k\\EntityFramework\\src\\\r\nEntityFramework.Core\\DbContext.cs:line 214\r\n   at MultiInclude2.Program.Main(String[] args) in D:\\Projects\\MultiInclude2\\Mul\r\ntiInclude2\\Program.cs:line 133"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/69269414","html_url":"https://github.com/aspnet/EntityFramework/issues/1373#issuecomment-69269414","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1373","id":69269414,"user":{"login":"maumar","id":1591930,"avatar_url":"https://avatars.githubusercontent.com/u/1591930?v=3","gravatar_id":"","url":"https://api.github.com/users/maumar","html_url":"https://github.com/maumar","followers_url":"https://api.github.com/users/maumar/followers","following_url":"https://api.github.com/users/maumar/following{/other_user}","gists_url":"https://api.github.com/users/maumar/gists{/gist_id}","starred_url":"https://api.github.com/users/maumar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maumar/subscriptions","organizations_url":"https://api.github.com/users/maumar/orgs","repos_url":"https://api.github.com/users/maumar/repos","events_url":"https://api.github.com/users/maumar/events{/privacy}","received_events_url":"https://api.github.com/users/maumar/received_events","type":"User","site_admin":false},"created_at":"2015-01-08T23:28:23Z","updated_at":"2015-01-08T23:28:23Z","body":"Key are explicitly defined in both cases - I would expect exact same behavior if only property name is changed."}}