{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13077","repository_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore","labels_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13077/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13077/comments","events_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13077/events","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/13077","id":352933549,"node_id":"MDU6SXNzdWUzNTI5MzM1NDk=","number":13077,"title":"Join with non-anonymous type followed by GroupBy cannot be translated","user":{"login":"byrnedo","id":5528491,"node_id":"MDQ6VXNlcjU1Mjg0OTE=","avatar_url":"https://avatars1.githubusercontent.com/u/5528491?v=4","gravatar_id":"","url":"https://api.github.com/users/byrnedo","html_url":"https://github.com/byrnedo","followers_url":"https://api.github.com/users/byrnedo/followers","following_url":"https://api.github.com/users/byrnedo/following{/other_user}","gists_url":"https://api.github.com/users/byrnedo/gists{/gist_id}","starred_url":"https://api.github.com/users/byrnedo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/byrnedo/subscriptions","organizations_url":"https://api.github.com/users/byrnedo/orgs","repos_url":"https://api.github.com/users/byrnedo/repos","events_url":"https://api.github.com/users/byrnedo/events{/privacy}","received_events_url":"https://api.github.com/users/byrnedo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-08-22T12:33:19Z","updated_at":"2018-08-28T06:47:59Z","closed_at":null,"author_association":"NONE","body":"If I do a `Join` and project to something other than an anonymous object and then do a `GroupBy`, this groupby gets evaluated locally.\r\n\r\n```\r\n: Microsoft.EntityFrameworkCore.Query[20500]\r\n      => Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor\r\n      The LINQ expression 'GroupBy(new <>f__AnonymousType0`1(BrandName = [b].BrandName), new GroupedResult() {BrandName = [b].BrandName, Vin = [c].Vin, Rating = [b].Rating})' could not be translated and will be evaluated locally.\r\nwarn: Microsoft.EntityFrameworkCore.Query[20500]\r\n      => Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor\r\n      The LINQ expression 'Count()' could not be translated and will be evaluated locally.\r\nwarn: Microsoft.EntityFrameworkCore.Query[20500]\r\n      => Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor\r\n      The LINQ expression 'Count()' could not be translated and will be evaluated locally.\r\n```\r\n\r\n### Steps to reproduce\r\n\r\n\r\nF\r\n```c#\r\n\r\nclass Program {\r\n        class GroupedResult {\r\n            public string BrandName {get;set;}\r\n            public int Rating {get;set;}\r\n            public string Vin {get;set;}\r\n        }\r\n\r\n\r\n        class MyTestContext : DbContext {\r\n            public virtual DbSet<Brand> Brands {get;set;}\r\n\r\n            public class Brand {\r\n                [Key]\r\n                public string BrandName {get;set;}\r\n                public int Rating {get;set;}\r\n            }\r\n\r\n            public class Car\r\n            {\r\n                [Key]\r\n                public int Key { get; set; }\r\n\r\n                [Required]\r\n                [StringLength(8)]\r\n                public string Vin { get; set; }\r\n\r\n                [Required]\r\n                public string Year { get; set; }\r\n\r\n                [Required]\r\n                public string Brand { get; set; }\r\n\r\n                [Required]\r\n                public string Color { get; set; }\r\n\r\n                [Required]\r\n                public DateTime DateLastModified { get; set; }\r\n            }\r\n\r\n            public static readonly LoggerFactory MyLoggerFactory = new LoggerFactory(new[] { new ConsoleLoggerProvider((filter, includeScopes) => true, true) });\r\n\r\n            public virtual DbSet<Car> Cars { get; set; }\r\n\r\n            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)\r\n            {\r\n                optionsBuilder.UseLoggerFactory(MyLoggerFactory); // Warning: Do not create a new ILoggerFactory instance each time \r\n                optionsBuilder.EnableSensitiveDataLogging();\r\n\r\n                optionsBuilder.UseSqlServer(@\"Server=(localdb)\\mssqllocaldb;Database=CarsEF20;Trusted_Connection=True;\");\r\n            }\r\n        }\r\n\r\n       \r\n\r\n        static void Main(string[] args)\r\n        {\r\n           \r\n\r\n            var config = ParsingConfig.DefaultEFCore21;\r\n            config.CustomTypeProvider = new C();\r\n\r\n            var context = new MyTestContext();\r\n\r\n            //context.Database.EnsureDeleted();\r\n            context.Database.EnsureCreated();\r\n\r\n            var dateLastModified = new DateTime(2018, 1, 15);\r\n\r\n            if (!context.Brands.Any())\r\n            {\r\n                context.Brands.Add(new MyTestContext.Brand { BrandName = \"Ford\", Rating = 9});\r\n                context.Brands.Add(new MyTestContext.Brand { BrandName = \"Fiat\", Rating = 6});\r\n                context.Brands.Add(new MyTestContext.Brand { BrandName = \"Alfa\", Rating = 4});\r\n                context.SaveChanges();\r\n\r\n            }\r\n            if (!context.Cars.Any())\r\n            {\r\n                context.Cars.Add(new MyTestContext.Car { Brand = \"Ford\", Color = \"Blue\", Vin = \"yes\", Year = \"2017\", DateLastModified = dateLastModified });\r\n                context.Cars.Add(new MyTestContext.Car { Brand = \"Fiat\", Color = \"Red\", Vin = \"yes\", Year = \"2016\", DateLastModified = dateLastModified.AddDays(1) });\r\n                context.Cars.Add(new MyTestContext.Car { Brand = \"Alfa\", Color = \"Black\", Vin = \"no\", Year = \"1979\", DateLastModified = dateLastModified.AddDays(2) });\r\n                context.Cars.Add(new MyTestContext.Car { Brand = \"Alfa\", Color = \"Black\", Vin = \"a%bc\", Year = \"1979\", DateLastModified = dateLastModified.AddDays(3) }); ;\r\n                context.SaveChanges();\r\n            }\r\n\r\n\r\n            // Gets evaluated locally\r\n            var g3 = context.Cars.Join(context.Brands, c => c.Brand, b => b.BrandName, (c,b) => new GroupedResult{BrandName = b.BrandName, Vin = c.Vin, Rating = b.Rating})\r\n            .GroupBy(x => new {x.BrandName}).Select(x => new{ Brand= x.Key.BrandName, CountValue2 = x.Count() }).ToDynamicList();\r\n            Console.WriteLine(\"GroupBy @ database {0}\", JsonConvert.SerializeObject(g3, Formatting.Indented));\r\n\r\n            // works\r\n            var g4 = context.Cars.Join(context.Brands, c => c.Brand, b => b.BrandName, (c,b) => new {BrandName = b.BrandName, Vin = c.Vin, Rating = b.Rating})\r\n            .GroupBy(x => new {x.BrandName}).Select(x => new{ Brand= x.Key.BrandName, CountValue2 = x.Count() }).ToDynamicList();\r\n            Console.WriteLine(\"GroupBy @ database {0}\", JsonConvert.SerializeObject(g3, Formatting.Indented));\r\n        }\r\n}\r\n\r\n```\r\n\r\n### Further technical details\r\nEF Core version:  2.1.1\r\nDatabase Provider: Microsoft.EntityFrameworkCore.SqlServer\r\nOperating system: mac\r\nIDE: vscode"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/comments/416470335","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/13077#issuecomment-416470335","issue_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13077","id":416470335,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNjQ3MDMzNQ==","user":{"login":"byrnedo","id":5528491,"node_id":"MDQ6VXNlcjU1Mjg0OTE=","avatar_url":"https://avatars1.githubusercontent.com/u/5528491?v=4","gravatar_id":"","url":"https://api.github.com/users/byrnedo","html_url":"https://github.com/byrnedo","followers_url":"https://api.github.com/users/byrnedo/followers","following_url":"https://api.github.com/users/byrnedo/following{/other_user}","gists_url":"https://api.github.com/users/byrnedo/gists{/gist_id}","starred_url":"https://api.github.com/users/byrnedo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/byrnedo/subscriptions","organizations_url":"https://api.github.com/users/byrnedo/orgs","repos_url":"https://api.github.com/users/byrnedo/repos","events_url":"https://api.github.com/users/byrnedo/events{/privacy}","received_events_url":"https://api.github.com/users/byrnedo/received_events","type":"User","site_admin":false},"created_at":"2018-08-28T06:47:59Z","updated_at":"2018-08-28T06:47:59Z","author_association":"NONE","body":"@smitpatel \r\nMy use case is that I build up the query in several stages (each being a class/function).\r\n\r\nThe first stage is the `from` and `join` clauses.\r\nSecond stages applies the `where`.\r\nThird stage applies the `select`, `group by` and `order by`.\r\n\r\nI wanted to be able to pass a typed `IQueryable` from the first stage to the second stage.\r\n\r\nMy workaround right now is to do all the joins as properties of an entity instead, which is possibly more correct anyway."}}
{"actor":{"display_login":"byrnedo"}}