-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The LINQ expression 'ProjectionBindingExpression: 0/1/2' could not be translated. #28125
Comments
We need full repro code here for us to investigate. |
@smitpatel
Query:
Output in EF6:
Output/Exceptions in EFCore 7_Preview4:
x21 = Exception:
|
Any update on this guys? I get this same problem in EFCore version 7.0.2. @ankitmatrix08 did this exception go away? What did you do without havng to rewrite your query? |
This looks like a GroupBy-related issue... Simplified minimal repro: _ = ctx.UserSiteAccesses
.GroupBy(u => u.CreatedById)
.Select(g => new { Id = g.Key, Entity = g.FirstOrDefault() })
.Join(
ctx.UserSiteAccesses,
x => x.Id,
u => u.UserId,
(x, u) => new { Entity = u, u.Id })
.ToList(); Unless I'm mistaken, this specific query can be simplified to the following, which does work: _ = ctx.UserSiteAccesses
.GroupBy(u => u.CreatedById)
.Select(g => ctx.UserSiteAccesses.FirstOrDefault(u2 => u2.Id == g.FirstOrDefault().CreatedById))
.ToList(); |
Unfortunately we could not effort to make changes to the original query and wished it could run seamlessly as in EF6 - hence there was no solution for us and we had to back out from upgrading to EF Core :( |
Hello. I have faced with the same problem during migration from EF6.4.4 to EF Core 7.0.13. There is minimal reproducible example: internal class Program
{
static void Main(string[] args)
{
using var context = new FooBarContext();
var groupedFoosQuery = context.Foos
.Where(f => f.TypeId > 5)
.GroupBy(
f => f.ObjectId,
(_, list) => list.OrderByDescending(f => f.FooId).First());
var query =
from foo in groupedFoosQuery
join bar in context.Bars
on new { ObjectId = foo.ObjectId, TypeId = foo.TypeId } equals
new { ObjectId = bar.ObjectId, TypeId = bar.TypeId }
into bars
select new { Foo = foo, Bars = bars };
var result = query.ToList();
}
}
public class FooBarContext : DbContext
{
public DbSet<Foo> Foos { get; set; }
public DbSet<Bar> Bars { get; set; }
public string DbPath { get; }
public FooBarContext()
{
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
DbPath = Path.Join(path, "foobar.db");
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={DbPath}");
}
public class Foo
{
public int FooId { get; set; }
public int ObjectId { get; set; }
public int TypeId { get; set; }
public string FooName { get; set; }
}
public class Bar
{
public int BarId { get; set; }
public int ObjectId { get; set; }
public int TypeId { get; set; }
public string BarName { get; set; }
} Error:
Stack Trace:
EF Core version: 7.0.13 |
I'm facing the same error when moving 2.2 to 6 |
facing the same issue, any update ? |
This issue is currently in the backlog. There's a good chance we'll do a general push to improve GroupBy support and fix bugs for EF 10, but it's unlikely to happen for 9. In the meantime, see above for workaround possibilities that involve modifying the query. |
The below query works fine with EF6 and also produces correct SQL but fails with EFCore 7.0
I have taken a sample code out of a long LINQ expression, essentially when a LINQ having projection as 'x2' below is used in another LINQ expression without specifying client evaluation then EFCore throws error:
Include verbose output
Stack Trace:
EF6 Generated SQL:
Include provider and version information
EF Core version: 7.0.0-preview.4.22229.2
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Win 10 Pro
IDE: Visual Studio 2022 v17.0.4
The text was updated successfully, but these errors were encountered: