You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The below example code results in client-side evaluation of the "take" operation. It works if I move the "take" before the GroupJoin.
The LINQ expression 'Take(__p_0)' could not be translated and will be evaluated locally.'.
In my head the SQL query would be the same in either case (the joined rows should not affect the count/order of the parent rows, after all), so I would expect Take to work on both sides of the GroupJoin.
Steps to reproduce
usingMicrosoft.EntityFrameworkCore;usingMicrosoft.EntityFrameworkCore.Diagnostics;usingMicrosoft.Extensions.Logging;usingMicrosoft.Extensions.Logging.Debug;usingSystem;usingSystem.Linq;namespaceConsoleApp14{internalclassProgram{publicstaticreadonlyGuidParent1Id=newGuid("bcee42c7-ad08-4a43-b9ea-ecb62939666e");publicstaticreadonlyGuidParent2Id=newGuid("d65de666-7a3c-49bb-90e2-c780d10832aa");publicstaticreadonlyGuidChild1Id=newGuid("5d846ff2-9db8-4a45-a939-3746df161eb4");publicstaticreadonlyGuidChild2Id=newGuid("7dcdc71c-d4c9-4d79-a62a-10e9545f4e21");privatestaticvoidMain(string[]args){using(vardc=newDataContext()){varjoined=dc.Parent//.Take(1) // Here it is fine..GroupJoin(dc.Child, p =>p.Id, c =>c.ParentId,(parent,children)=>new{parent,children}).Take(1)// Here it forces client-side evaluation..ToArray();Console.WriteLine($"{joined.Length} rows.");}}}publicclassParentRow{publicGuidId{get;set;}publicDateTimeOffsetCreated{get;set;}}publicclassChildRow{publicGuidId{get;set;}publicGuidParentId{get;set;}publicDateTimeOffsetCreated{get;set;}}publicclassDataContext:DbContext{publicDbSet<ParentRow>Parent{get;set;}publicDbSet<ChildRow>Child{get;set;}publicDataContext(){}protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder){optionsBuilder.ConfigureWarnings(warnings =>{warnings.Throw(RelationalEventId.QueryClientEvaluationWarning);});optionsBuilder.EnableSensitiveDataLogging();optionsBuilder.UseLoggerFactory(MyLoggerFactory);if(!optionsBuilder.IsConfigured)optionsBuilder.UseSqlServer("Server=(local);Database=EFCore_Issue_Repro;Trusted_Connection=True;");}publicstaticreadonlyLoggerFactoryMyLoggerFactory=newLoggerFactory(new[]{newDebugLoggerProvider((category,level)=>true)});protectedoverridevoidOnModelCreating(ModelBuildermodelBuilder){modelBuilder.Entity<ParentRow>().HasData(newParentRow{Id=Program.Parent1Id,Created=DateTimeOffset.UtcNow},newParentRow{Id=Program.Parent2Id,Created=DateTimeOffset.UtcNow});modelBuilder.Entity<ChildRow>().HasData(newChildRow{Id=Program.Child1Id,ParentId=Program.Parent1Id,Created=DateTimeOffset.UtcNow},newChildRow{Id=Program.Child2Id,ParentId=Program.Parent2Id,Created=DateTimeOffset.UtcNow});}}}
Further technical details
EF Core version: 2.2.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 1809
IDE: Visual Studio 2017 15.9.5
The text was updated successfully, but these errors were encountered:
The query compiler can translate group-join by using a left join with an ordering, reading in the results chunked by the parents' ids.
For the 'before' case, the query is selecting one parent and then group-joining its children. In other words, the parent row comes from a SELECT TOP(1) subquery, onto which the children are joined.
But when you have the Take after the group join, while the resulting data should be the same, the query compiler's options for translation are not the same. It can't add TOP (1) to the query that was built so far because there may be more than one row due to joining more than one child for the first parent (well, it could, but it would have to use FOR JSON or FOR XML or something to marshall the children out in a single row.)
The below example code results in client-side evaluation of the "take" operation. It works if I move the "take" before the GroupJoin.
In my head the SQL query would be the same in either case (the joined rows should not affect the count/order of the parent rows, after all), so I would expect Take to work on both sides of the GroupJoin.
Steps to reproduce
Further technical details
EF Core version: 2.2.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 1809
IDE: Visual Studio 2017 15.9.5
The text was updated successfully, but these errors were encountered: