{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/6554","repository_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore","labels_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/6554/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/6554/comments","events_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/6554/events","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/6554","id":177386059,"node_id":"MDU6SXNzdWUxNzczODYwNTk=","number":6554,"title":"EF mismatches the inherited navigation property with the inverse key property","user":{"login":"Sojaner","id":1634835,"node_id":"MDQ6VXNlcjE2MzQ4MzU=","avatar_url":"https://avatars2.githubusercontent.com/u/1634835?v=4","gravatar_id":"","url":"https://api.github.com/users/Sojaner","html_url":"https://github.com/Sojaner","followers_url":"https://api.github.com/users/Sojaner/followers","following_url":"https://api.github.com/users/Sojaner/following{/other_user}","gists_url":"https://api.github.com/users/Sojaner/gists{/gist_id}","starred_url":"https://api.github.com/users/Sojaner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sojaner/subscriptions","organizations_url":"https://api.github.com/users/Sojaner/orgs","repos_url":"https://api.github.com/users/Sojaner/repos","events_url":"https://api.github.com/users/Sojaner/events{/privacy}","received_events_url":"https://api.github.com/users/Sojaner/received_events","type":"User","site_admin":false},"labels":[{"id":403964217,"node_id":"MDU6TGFiZWw0MDM5NjQyMTc=","url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/labels/closed-fixed","name":"closed-fixed","color":"777777","default":false},{"id":76481852,"node_id":"MDU6TGFiZWw3NjQ4MTg1Mg==","url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/labels/type-bug","name":"type-bug","color":"f7c6c7","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/milestones/19","html_url":"https://github.com/aspnet/EntityFrameworkCore/milestone/19","labels_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/milestones/19/labels","id":1748298,"node_id":"MDk6TWlsZXN0b25lMTc0ODI5OA==","number":19,"title":"1.1.0-preview1","description":"","creator":{"login":"rowanmiller","id":4741851,"node_id":"MDQ6VXNlcjQ3NDE4NTE=","avatar_url":"https://avatars2.githubusercontent.com/u/4741851?v=4","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":0,"closed_issues":263,"state":"closed","created_at":"2016-05-04T18:23:47Z","updated_at":"2017-09-30T03:31:20Z","due_on":null,"closed_at":"2016-10-25T19:07:33Z"},"comments":11,"created_at":"2016-09-16T09:55:13Z","updated_at":"2018-07-05T15:41:31Z","closed_at":"2016-10-14T21:14:55Z","author_association":"NONE","body":"**Steps to reproduce**\nConsider these View Models:\n\n``` C#\npublic abstract class PersonBaseViewModel\n{\n    public int Id { get; set; }\n    public string FirstName { get; set; }\n    public string LastName { get; set; }\n    public string IdNumber { get; set; }\n\n    public virtual CityViewModel CityVM { get; set; }\n}\n\npublic abstract class ServicePersonViewModel: PersonBaseViewModel\n{\n    public string PersonnelNumber { get; set; }\n}\n\npublic class CitizenViewModel : PersonBaseViewModel\n{\n    //...\n}\n\npublic class PoliceViewModel : ServicePersonViewModel\n{\n    //...\n}\n\npublic class CityViewModel\n{\n    public int Id { get; set; }\n\n    public ICollection<CitizenViewModel> People { get; set; }\n    public ICollection<PoliceViewModel> Securities { get; set; }\n}\n```\n\nThe migrations being generated include codes similar to these:\n\n``` C#\nmodelBuilder.Entity(\"PersonBaseViewModel\", b =>\n{\n   //...\n\n   b.Property<int?>(\"CityVMId\");\n\n   //...\n\n   b.HasIndex(\"CityVMId\");\n\n   //...\n});\n\nmodelBuilder.Entity(\"CitizenViewModel\", b =>\n{\n   b.HasBaseType(\"PersonBaseViewModel\");\n\n   //...\n\n   b.Property<int?>(\"CityViewModelId\");\n\n   //...\n\n   b.HasIndex(\"CityViewModelId\");\n\n   //...\n });\n\nmodelBuilder.Entity(\"PoliceViewModel\", b =>\n{\n   b.HasBaseType(\"ServicePersonViewModel\");\n\n   //...\n\n   b.Property<int?>(\"CityViewModelId\");\n\n   //...\n\n   b.HasIndex(\"CityViewModelId\");\n\n   //...\n });\n\n //--------------------------------------------------\n\nmodelBuilder.Entity(\"PersonBaseViewModel\", b =>\n{\n   b.HasOne(\"CityViewModel\", \"CityVM\")\n    .WithMany()\n    .HasForeignKey(\"CityVMId\");\n});\n\nmodelBuilder.Entity(\"CitizenViewModel\", b =>\n{\n   b.HasOne(\"CityViewModel\", \"CityVM\")\n    .WithMany()\n    .HasForeignKey(\"CityViewModelId\");\n});\n\nmodelBuilder.Entity(\"PoliceViewModel\", b =>\n{\n   b.HasOne(\"CityViewModel\", \"CityVM\")\n    .WithMany()\n    .HasForeignKey(\"CityViewModelId\");\n});\n\n//--------------------------------------------------\n\nmigrationBuilder.CreateTable(\nname: \"PersonBases\",\ncolumns: table => new\n{\n    //...\n\n       CityVMId = table.Column<int>(nullable: true),\n\n    //...\n\n    CityViewModelId = table.Column<int>(nullable: true),\n\n    //...\n},\nconstraints: table =>\n{\n    table.PrimaryKey(\"PK_PersonBases\", x => x.Id);\n    table.ForeignKey(\n        name: \"FK_PersonBases_Cities_CityVMId\",\n        column: x => x.CityVMId,\n        principalTable: \"Cities\",\n        principalColumn: \"Id\",\n        onDelete: ReferentialAction.Restrict);\n    table.ForeignKey(\n        name: \"FK_PersonBases_Cities_CityViewModelId\",\n        column: x => x.CityViewModelId,\n        principalTable: \"Cities\",\n        principalColumn: \"Id\",\n        onDelete: ReferentialAction.Restrict);\n});\n```\n\n**The issue**\nAs you can see, there are two different foreign keys being generated between Cities and PersonBases tables, however the CityVMId column is always empty and contains NULLs.\n\nRemoving the extra foreign key from migrations fixes the database creation, however when inserting data into the table using EF Core, an exception with message 'Column CityVMId could not be found' (Or something similar) is being raised.\n\nTherefore, an empty column for CityVMId must be existing in the database for the EF Core to work when inserting/updating data.\n\n**Further technical details**\nDot Net Core version: 1.0.1 (1.0.0-preview2-003131/DotNetCore.1.0.1-VS2015Tools.Preview2.0.2)\nEntity Framework Core version: 1.0.1 (1.0.0-preview2-21431)\nOperating system: Windows 10 x64\nVisual Studio version: VS 2015 Update 3\n"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/comments/402765326","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/6554#issuecomment-402765326","issue_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/6554","id":402765326,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMjc2NTMyNg==","user":{"login":"srungta","id":31416811,"node_id":"MDQ6VXNlcjMxNDE2ODEx","avatar_url":"https://avatars0.githubusercontent.com/u/31416811?v=4","gravatar_id":"","url":"https://api.github.com/users/srungta","html_url":"https://github.com/srungta","followers_url":"https://api.github.com/users/srungta/followers","following_url":"https://api.github.com/users/srungta/following{/other_user}","gists_url":"https://api.github.com/users/srungta/gists{/gist_id}","starred_url":"https://api.github.com/users/srungta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/srungta/subscriptions","organizations_url":"https://api.github.com/users/srungta/orgs","repos_url":"https://api.github.com/users/srungta/repos","events_url":"https://api.github.com/users/srungta/events{/privacy}","received_events_url":"https://api.github.com/users/srungta/received_events","type":"User","site_admin":false},"created_at":"2018-07-05T15:41:30Z","updated_at":"2018-07-05T15:41:30Z","author_association":"NONE","body":"@Sojaner @AndriySvyryd \r\nI have a similar issue.\r\nA part of our models is as below.\r\n``` csharp\r\n    public abstract class IntentBaseModel \r\n    {\r\n        /// <inheritdoc />\r\n        [Key]\r\n        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]\r\n        public Guid Id { get; set; }\r\n    }\r\n\r\n    [Table(\"IntentStaging\")]\r\n    public class IntentStaging : IntentBaseModel\r\n    {\r\n        /// <summary>\r\n        /// Gets or sets foreign key reference in topic table.\r\n        /// </summary>\r\n        /// <value>\r\n        /// The topics associated with this intent.\r\n        /// </value>\r\n        public virtual ICollection<TopicStaging> Topics { get; set; }\r\n    }\r\n\r\n    [Table(\"TopicStaging\")]\r\n    public class TopicStaging \r\n    {\r\n       /// <inheritdoc />\r\n        [Key]\r\n        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]\r\n        public Guid Id { get; set; }\r\n    }\r\n```\r\nThis created a migration that added two foreign keys `IntentId` and `IntentStagingId` to the TopicStaging table.The migrations have already been applied to the database. Is there any way to drop the extra `IntentStagingId` column and maintain a single reference?\r\n\r\nMy main concern is that when i try to include the topics from intents, it refers to the IntentStagingId column which always has a null value.\r\nAny help would be appreciated."}}
{"actor":{"display_login":"srungta"}}