{"action":"opened","issue":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/12116","repository_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore","labels_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/12116/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/12116/comments","events_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/12116/events","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/12116","id":325669900,"number":12116,"title":"DbQuery<T> with .Include related entities","user":{"login":"wernerbarnard","id":6905546,"avatar_url":"https://avatars3.githubusercontent.com/u/6905546?v=4","gravatar_id":"","url":"https://api.github.com/users/wernerbarnard","html_url":"https://github.com/wernerbarnard","followers_url":"https://api.github.com/users/wernerbarnard/followers","following_url":"https://api.github.com/users/wernerbarnard/following{/other_user}","gists_url":"https://api.github.com/users/wernerbarnard/gists{/gist_id}","starred_url":"https://api.github.com/users/wernerbarnard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wernerbarnard/subscriptions","organizations_url":"https://api.github.com/users/wernerbarnard/orgs","repos_url":"https://api.github.com/users/wernerbarnard/repos","events_url":"https://api.github.com/users/wernerbarnard/events{/privacy}","received_events_url":"https://api.github.com/users/wernerbarnard/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-23T11:49:07Z","updated_at":"2018-05-23T11:49:07Z","closed_at":null,"author_association":"NONE","body":"I want to use the new DbQuery / Query Types to query a SQL Server indexed view that does some joins, to simply the structure needed in EF Core - but upon querying, I need to include some relational entities.  How do you do that?\r\n\r\n```\r\nException message: InvalidOperationException: Unable to create a foreign key with the query type 'StoryQuery' as the principal type. Only entity types are allowed as foreign key principal types.\r\n```\r\n\r\n### Steps to reproduce\r\n\r\n\r\n```c#\r\n    public Story\r\n    {\r\n        public long Id { get; set; }\r\n        public DateTime StoryDate { get; set; }\r\n        public ICollection<StoryTag> StoryTags { get; set; }\r\n    }\r\n\r\n    public class StoryTag\r\n    {\r\n        public long Id { get; set; }\r\n        public long StoryId { get; set; }\r\n        public long TagId { get; set; }\r\n        public string TagText { get; set; }\r\n    }\r\n\r\n            var result = await context.Stories()\r\n                .Where(predicate)\r\n                .Include(s => s.StoryTag)\r\n                .OrderByDescending(s => s.StoryDate)\r\n                .Skip(0)\r\n                .Take(10)\r\n                .ToListAsync(cancellationToken);\r\n```\r\n\r\nIf I add [InverseProperty] or [ForeignKey] to any of the navigation properties in the above, then I get the above-mentioned error.  How do we include the related entities when querying DbQuery instead of DbSet ?\r\n\r\n### Further technical details\r\nEF Core version: 2.1.0-rc1-final\r\nDatabase Provider: Microsoft.EntityFrameworkCore.SqlServer\r\nOperating system: Windows 10 x64\r\nIDE: JetBrains Rider 2018.1\r\n"}}
{"actor":{"display_login":"wernerbarnard"}}