{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1286","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1286/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1286/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1286/events","html_url":"https://github.com/aspnet/EntityFramework/issues/1286","id":51860433,"number":1286,"title":"Mapping :: optional One To One mapping throws, expecting PK on the principal to be nullable","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":[{"url":"https://api.github.com/repos/aspnet/EntityFramework/labels/1+-+Working+%3C%3D+9","name":"1 - Working <= 9","color":"CCCCCC"},{"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":"mikary","id":6787717,"avatar_url":"https://avatars.githubusercontent.com/u/6787717?v=3","gravatar_id":"","url":"https://api.github.com/users/mikary","html_url":"https://github.com/mikary","followers_url":"https://api.github.com/users/mikary/followers","following_url":"https://api.github.com/users/mikary/following{/other_user}","gists_url":"https://api.github.com/users/mikary/gists{/gist_id}","starred_url":"https://api.github.com/users/mikary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikary/subscriptions","organizations_url":"https://api.github.com/users/mikary/orgs","repos_url":"https://api.github.com/users/mikary/repos","events_url":"https://api.github.com/users/mikary/events{/privacy}","received_events_url":"https://api.github.com/users/mikary/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/7","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/7/labels","id":666128,"number":7,"title":"7.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":160,"closed_issues":81,"state":"open","created_at":"2014-05-21T19:25:32Z","updated_at":"2015-01-08T23:32:37Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2014-12-12T22:26:16Z","updated_at":"2015-01-08T23:55:12Z","closed_at":null,"body":"Consider the following:\r\n\r\n```\r\npublic class Person\r\n    {\r\n        public int Id { get; set; }\r\n        public string Name { get; set; }\r\n        public House SummerHouse { get; set; }\r\n        public int? SummerHouseId { get; set; }\r\n    }\r\n\r\n    public class House\r\n    {\r\n        public int Id { get; set; }\r\n        public string Name { get; set; }\r\n\r\n        public Person Owner { get; set; }\r\n    }\r\n\r\n    public class MyContext : DbContext\r\n    {\r\n        public DbSet<Person> People { get; set; }\r\n\r\n        public DbSet<House> Houses { get; set; }\r\n\r\n        protected override void OnModelCreating(ModelBuilder modelBuilder)\r\n        {\r\n            modelBuilder.Entity<House>().Property(h => h.Id);\r\n            modelBuilder.Entity<Person>().Property(h => h.Id);\r\n            modelBuilder.Entity<Person>().OneToOne(p => p.SummerHouse, h => h.Owner).Required(false).ForeignKey<Person>(h => h.SummerHouseId);\r\n        }\r\n\r\n        protected override void OnConfiguring(DbContextOptions options)\r\n        {\r\n            options.UseSqlServer(new SqlConnectionStringBuilder { DataSource = \".\", InitialCatalog = \"NullableOneToOne\", IntegratedSecurity = true }.ToString());\r\n        }\r\n    }\r\n```\r\n\r\nthis throws the following:\r\n\r\nUnhandled Exception: System.InvalidOperationException: The property 'Id' on entity type 'House' cannot be marked as nullable/optional because the type of the property is 'Int32' which is not a nullable type. Any property can be marked as non-nullable/required, but only properties of nullable types can be marked as nullable/optional.\r\n   at Microsoft.Data.Entity.Metadata.Property.set_IsNullable(Nullable`1 value)\r\n   at Microsoft.Data.Entity.Metadata.ForeignKey.set_IsRequired(Nullable`1 value)\r\n\r\n   at Microsoft.Data.Entity.Metadata.Internal.InternalRelationshipBuilder.Requir\r\ned(Boolean required)\r\n   at Microsoft.Data.Entity.Metadata.ModelBuilder.EntityBuilder.OneToOneBuilder.\r\nRequired(Boolean required)\r\n   at NullableOneToOne.MyContext.OnModelCreating(ModelBuilder modelBuilder) in D\r\n:\\Projects\\NullableOneToOne\\NullableOneToOne\\Program.cs:line 41\r\n   at Microsoft.Data.Entity.Infrastructure.ModelSourceHelpers.OnModelCreating(Db\r\nContext context, ModelBuilder modelBuilder)\r\n   at Microsoft.Data.Entity.Infrastructure.DefaultModelSource.CreateModel(DbCont\r\next context, IModelBuilderFactory modelBuilderFactory)\r\n   at Microsoft.Data.Entity.Infrastructure.DefaultModelSource.<>c__DisplayClass0\r\n.<GetModel>b__1(Type k)\r\n   at Microsoft.Data.Entity.Utilities.ThreadSafeDictionaryCache`2.GetOrAdd(TKey\r\nkey, Func`2 factory)\r\n   at Microsoft.Data.Entity.Infrastructure.DefaultModelSource.GetModel(DbContext\r\n context, IModelBuilderFactory modelBuilderFactory)\r\n   at Microsoft.Data.Entity.Infrastructure.DbContextServices.CreateModel()\r\n   at Microsoft.Data.Entity.Utilities.LazyRef`1.get_Value()\r\n   at Microsoft.Data.Entity.Infrastructure.DbContextServices.get_Model()\r\n   at Microsoft.Data.Entity.Infrastructure.DbContextServices.<>c__DisplayClass7.\r\n<get_ModelFactory>b__9()\r\n   at Microsoft.Data.Entity.Utilities.LazyRef`1.get_Value()\r\n   at Microsoft.Data.Entity.Infrastructure.DbContextService`1.get_Service()\r\n   at Microsoft.Data.Entity.Infrastructure.Database.get_Model()\r\n   at Microsoft.Data.Entity.Infrastructure.Database.EnsureDeleted()\r\n   at NullableOneToOne.Program.Main(String[] args) in D:\\Projects\\NullableOneToO\r\nne\\NullableOneToOne\\Program.cs:line 57\r\n\r\n<!---\r\n@huboard:{\"order\":1308.0,\"milestone_order\":1286,\"custom_state\":\"\"}\n-->\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/69272216","html_url":"https://github.com/aspnet/EntityFramework/issues/1286#issuecomment-69272216","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1286","id":69272216,"user":{"login":"mikary","id":6787717,"avatar_url":"https://avatars.githubusercontent.com/u/6787717?v=3","gravatar_id":"","url":"https://api.github.com/users/mikary","html_url":"https://github.com/mikary","followers_url":"https://api.github.com/users/mikary/followers","following_url":"https://api.github.com/users/mikary/following{/other_user}","gists_url":"https://api.github.com/users/mikary/gists{/gist_id}","starred_url":"https://api.github.com/users/mikary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikary/subscriptions","organizations_url":"https://api.github.com/users/mikary/orgs","repos_url":"https://api.github.com/users/mikary/repos","events_url":"https://api.github.com/users/mikary/events{/privacy}","received_events_url":"https://api.github.com/users/mikary/received_events","type":"User","site_admin":false},"created_at":"2015-01-08T23:55:12Z","updated_at":"2015-01-08T23:55:12Z","body":"The exception is not thrown if the Required call follows the ForeignKey, rather than preceding it. Clearing labels to run back through triage."}}