{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5344","repository_url":"https://api.github.com/repos/aspnet/EntityFramework","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5344/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5344/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5344/events","html_url":"https://github.com/aspnet/EntityFramework/issues/5344","id":154501994,"number":5344,"title":"Multiple one-to-one relations create duplicate foreign key field.","user":{"login":"Kemaletdin","id":6124584,"avatar_url":"https://avatars.githubusercontent.com/u/6124584?v=3","gravatar_id":"","url":"https://api.github.com/users/Kemaletdin","html_url":"https://github.com/Kemaletdin","followers_url":"https://api.github.com/users/Kemaletdin/followers","following_url":"https://api.github.com/users/Kemaletdin/following{/other_user}","gists_url":"https://api.github.com/users/Kemaletdin/gists{/gist_id}","starred_url":"https://api.github.com/users/Kemaletdin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kemaletdin/subscriptions","organizations_url":"https://api.github.com/users/Kemaletdin/orgs","repos_url":"https://api.github.com/users/Kemaletdin/repos","events_url":"https://api.github.com/users/Kemaletdin/events{/privacy}","received_events_url":"https://api.github.com/users/Kemaletdin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aspnet/EntityFramework/labels/bug","name":"bug","color":"f7c6c7"},{"url":"https://api.github.com/repos/aspnet/EntityFramework/labels/pri0","name":"pri0","color":"e11d21"}],"state":"open","locked":false,"assignee":{"login":"AndriySvyryd","id":6539701,"avatar_url":"https://avatars.githubusercontent.com/u/6539701?v=3","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/EntityFramework/milestones/7","html_url":"https://github.com/aspnet/EntityFramework/milestones/1.0.0","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/7/labels","id":666128,"number":7,"title":"1.0.0","description":"","creator":{"login":"rowanmiller","id":4741851,"avatar_url":"https://avatars.githubusercontent.com/u/4741851?v=3","gravatar_id":"","url":"https://api.github.com/users/rowanmiller","html_url":"https://github.com/rowanmiller","followers_url":"https://api.github.com/users/rowanmiller/followers","following_url":"https://api.github.com/users/rowanmiller/following{/other_user}","gists_url":"https://api.github.com/users/rowanmiller/gists{/gist_id}","starred_url":"https://api.github.com/users/rowanmiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rowanmiller/subscriptions","organizations_url":"https://api.github.com/users/rowanmiller/orgs","repos_url":"https://api.github.com/users/rowanmiller/repos","events_url":"https://api.github.com/users/rowanmiller/events{/privacy}","received_events_url":"https://api.github.com/users/rowanmiller/received_events","type":"User","site_admin":false},"open_issues":102,"closed_issues":180,"state":"open","created_at":"2014-05-21T19:25:32Z","updated_at":"2016-05-17T18:59:42Z","due_on":null,"closed_at":null},"comments":7,"created_at":"2016-05-12T14:49:25Z","updated_at":"2016-05-17T20:09:32Z","closed_at":null,"body":"Have 2 entities\r\n```\r\n\r\npublic class Customer {\r\n  public int Id {get; set;}\r\n  public string Name {get; set;}\r\n  public int? ShipToAddressId {get; set;}\r\n  public int? BillToAddressId {get;set;}\r\n  public virtual CustomerAddress ShipToAddress {get;set;}\r\n  public virtual CustomerAddress BillToAddress {get;set}\r\n  public virtual ICollection<CustomerAddress> CustomerAddresses {get;set;} \r\n}\r\n\r\npublic class CustomerAddress {\r\n  public int Id {get;set;}\r\n  public int CustomerId {get;set;}\r\n  public string Name {get;set;}\r\n  public string Address {get;set;}\r\n  public virtual Customer Customer {get;set'}\r\n}\r\n```\r\n\r\nwith the `following` Fluent API in DbContext OnModelCreating method\r\n\r\n            var customeraddress = builder.Entity<CustomerAddress>();\r\n            customeraddress.HasKey(t => t.Id);\r\n            customeraddress.Property(t => t.Id).ValueGeneratedOnAdd();\r\n            customeraddress.Property(t => t.Name).IsRequired();\r\n            customeraddress.Property(t => t.Address).IsRequired();\r\n\r\n            var customer = builder.Entity<Customer>();\r\n            customer.HasKey(t => t.Id);\r\n            customer.Property(t => t.Id).ValueGeneratedOnAdd();\r\n            customer.Property(t => t.Name).IsRequired();\r\n            customer.HasOne(t => t.BillToAddress)\r\n                    .WithOne(c => c.Customer)\r\n                    .HasForeignKey<Customer>(f => f.BillToAddressId);\r\n            customer.HasOne(t => t.ShipToAddress)\r\n                    .WithOne(c => c.Customer)\r\n                    .HasForeignKey<Customer>(f => f.ShipToAddressId);   \r\n\r\n\r\nthis generates an extra field called \"BillToAddressId1\" in Customers Table instead of using already existing \"BillToAddressId\" field.\r\nSo Customers table gets created with both fields.\r\n\r\nthanks"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/219837987","html_url":"https://github.com/aspnet/EntityFramework/issues/5344#issuecomment-219837987","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5344","id":219837987,"user":{"login":"AndriySvyryd","id":6539701,"avatar_url":"https://avatars.githubusercontent.com/u/6539701?v=3","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},"created_at":"2016-05-17T20:09:32Z","updated_at":"2016-05-17T20:09:32Z","body":"We decided to throw in this case as it seems to be fairly common."}}