{"action":"closed","issue":{"url":"https://api.github.com/repos/msallin/SQLiteCodeFirst/issues/69","repository_url":"https://api.github.com/repos/msallin/SQLiteCodeFirst","labels_url":"https://api.github.com/repos/msallin/SQLiteCodeFirst/issues/69/labels{/name}","comments_url":"https://api.github.com/repos/msallin/SQLiteCodeFirst/issues/69/comments","events_url":"https://api.github.com/repos/msallin/SQLiteCodeFirst/issues/69/events","html_url":"https://github.com/msallin/SQLiteCodeFirst/issues/69","id":163768110,"number":69,"title":"Incorrect Self-Referencing FK created in special case entity names","user":{"login":"jjbutera","id":19984662,"avatar_url":"https://avatars.githubusercontent.com/u/19984662?v=3","gravatar_id":"","url":"https://api.github.com/users/jjbutera","html_url":"https://github.com/jjbutera","followers_url":"https://api.github.com/users/jjbutera/followers","following_url":"https://api.github.com/users/jjbutera/following{/other_user}","gists_url":"https://api.github.com/users/jjbutera/gists{/gist_id}","starred_url":"https://api.github.com/users/jjbutera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jjbutera/subscriptions","organizations_url":"https://api.github.com/users/jjbutera/orgs","repos_url":"https://api.github.com/users/jjbutera/repos","events_url":"https://api.github.com/users/jjbutera/events{/privacy}","received_events_url":"https://api.github.com/users/jjbutera/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/msallin/SQLiteCodeFirst/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":{"login":"msallin","id":7792779,"avatar_url":"https://avatars.githubusercontent.com/u/7792779?v=3","gravatar_id":"","url":"https://api.github.com/users/msallin","html_url":"https://github.com/msallin","followers_url":"https://api.github.com/users/msallin/followers","following_url":"https://api.github.com/users/msallin/following{/other_user}","gists_url":"https://api.github.com/users/msallin/gists{/gist_id}","starred_url":"https://api.github.com/users/msallin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msallin/subscriptions","organizations_url":"https://api.github.com/users/msallin/orgs","repos_url":"https://api.github.com/users/msallin/repos","events_url":"https://api.github.com/users/msallin/events{/privacy}","received_events_url":"https://api.github.com/users/msallin/received_events","type":"User","site_admin":false},"assignees":[{"login":"msallin","id":7792779,"avatar_url":"https://avatars.githubusercontent.com/u/7792779?v=3","gravatar_id":"","url":"https://api.github.com/users/msallin","html_url":"https://github.com/msallin","followers_url":"https://api.github.com/users/msallin/followers","following_url":"https://api.github.com/users/msallin/following{/other_user}","gists_url":"https://api.github.com/users/msallin/gists{/gist_id}","starred_url":"https://api.github.com/users/msallin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msallin/subscriptions","organizations_url":"https://api.github.com/users/msallin/orgs","repos_url":"https://api.github.com/users/msallin/repos","events_url":"https://api.github.com/users/msallin/events{/privacy}","received_events_url":"https://api.github.com/users/msallin/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2016-07-05T04:02:22Z","updated_at":"2016-07-09T09:27:38Z","closed_at":"2016-07-09T09:27:38Z","body":"This is a weird one in version 1.2.3.15. If you have an entity that begins with the plural of another entity, and it has a navigation property to that other entity, the FK is created incorrectly. Try the following:\r\n\r\n\tpublic class Foo\r\n\t{\r\n\t\tpublic int FooId { get; set; }\r\n\t\tpublic string Name { get; set; }\r\n\r\n\t\tprivate ICollection<FooStep> _FooSteps;\r\n\t\tpublic virtual ICollection<FooStep> FooSteps\r\n\t\t{\r\n\t\t\tget { return _FooSteps ?? (_FooSteps = new HashSet<FooStep>()); }\r\n\t\t\tset { _FooSteps = value; }\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class FooStep\r\n\t{\r\n\t\tpublic int FooStepId { get; set; }\r\n\t\tpublic int FooId { get; set; }\r\n\t\tpublic int Number { get; set; }\r\n\t\tpublic virtual Foo Foo { get; set; }\r\n\t}\r\n\r\nWhen the database is generated, instead of a FK to FooId being created in table FooSteps, it's created on the Foos table instead (so it ends up with a self-referenced FK). Weird!\r\n\r\nNote: I did not encounter this behavior in 1.2.2.14. It looks like the patch to support small entity names introduced this new bug.\r\n\r\nIf you change FooStep to anything else that doesn't have an \"S\" after Foo, then it generates fine. This generates the FK as expected on the FoobSteps table:\r\n\r\n\tpublic class FoobStep\r\n\t{\r\n\t\tpublic int FoobStepId { get; set; }\r\n\t\tpublic int FooId { get; set; }\r\n\t\tpublic int Number { get; set; }\r\n\t\tpublic virtual Foo Foo { get; set; }\r\n\t}\r\n"}}
{"actor":{"display_login":"msallin"}}