Closed KAJOOSH closed 2 years ago
A sample project was also attached for faster tracking: ConsoleApp_Test.zip
@maumar Can you take a look at this? In particular, whether or not it can be quirked back to the 6.0.1 behavior.
AppContext.SetSwitch("Microsoft.EntityFrameworkCore.Issue27102", true);
@KAJOOSH
problem: in #27102 we started matching group correlation predicate with predicate exactly when trying to lift it. The problem is that here the predicate is Exisits(subquery). They are both essentially identical, but for SelectExpression we (deliberately) perform reference comparison, so the check doesn't pass and we don't go into the lifting logic, even though we could/should.
@maumar Thanks for the review. Interestingly, I had a similar problem with #27102 and it was fixed with version 6.0.2! These two problems did not exist in .net 5 .. And now I need both and I can not disable #27102
@maumar I have a suggestion If it can be recognized that the blindness of the "context" is new, maybe this issue will be resolved?
@smitpatel to look at workarounds.
var query = db
.TicketTasks
.Where(x => x.isDone == false && (x.ActDepartment._DepartmentStaff.Any(c => c.UserID == 4) || x.ActUserID == 4))
.Select(x => x.InsertedDatePersian.Substring(0, 10))
.Skip(0)
.GroupBy(x => x)
.Select(g => new { Date = g.Key, Count = g.Count() })
.AsQueryable();
Select appropriate Grouping Key columns and required columns on which aggregate is being applied in projection, then apply Skip(0) to cause a subquery. This will make sure that complex columns are pushed inside subquery and lifting works to aggregate operator.
Same as #27266
This problem only occurs in version 6.0.2 and does not occur in version 6.0.1.
Repro
ConsoleApp.csproj:
ApplicationDbContext.cs:
ApplicationUser.cs:
Department.cs:
DepartmentStaff.cs:
Task.cs:
Program.cs:
Error
Query String
Query created in version 6.0.1:
Query created in version 6.0.2:
Include provider and version information
EF Core version: Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer) Target framework: (e.g. .NET 6.0) Operating system: IDE: (e.g. Visual Studio 2022 17.0.6)