-
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
[Regression] "Table not found with alias" for column access inside subquery predicate #35118
Comments
Confirmed regression from EF8. |
Stripped down repro: await using var context = new BlogContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
var results = await context.As
.SelectMany(a => context.Es.Where(g => a.Name == "A"))
.ToListAsync();
public class BlogContext : DbContext
{
public DbSet<A> As { get; set; }
public DbSet<E> Es { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer("Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0;Encrypt=false")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
}
public class A
{
public int Id { get; set; }
public string Name { get; set; }
}
public class E
{
public int Id { get; set; }
} |
Also reproes with: var results = await context.As
.Where(a => context.As.Where(g => a.Name == "A").Any())
.ToListAsync(); |
This turned out to be because of some special TPC predicate checks we have when applying WHERE, which implement OfType logic (removing TPC tables once the user narrows the hierarchy down). The logic specifically checks for a predicate that's a simple equality of the TPC discriminator column; the latter is identified by looking at the column's table to see if it's a TpcTablesExpression. Now, in 8.0, ColumnExpression referenced its table directly, so the check simply worked; but in 9.0, columns only have their table aliases, and the table must be resolved from the SelectExpression (our SQL tree is now a tree rather than a graph). The 9.0 logic simply assumes that the column's identifier would be found in the (current) SelectExpression, but when the column references a table from an outer query, the table isn't found in the inner SelectExpression and an exception is thrown. The fix in #35120 simply fails the check if the table isn't found on the current SelectExpression, and translates it as usual. The special logic should absolutely not apply for TpcTableExpressions in outer queries, since a predicate in a subquery doesn't narrow down the outer query's TPC table list. |
Fixes dotnet#35118 (cherry picked from commit 3d0b86d)
Fixes dotnet#35118 (cherry picked from commit 3d0b86d)
Have code working up to EF 8.0.11. After upgrading to EF 9 new exception is thrown. Code to reproduce is shown below (its cut out of a much more complex real use case, kept chopping down to this which I hope is small enough for you to see the issue)
Using VS 17.13.0 Preview 1.0 on Window 11. Works with EF 8.0.11 fails with following exception EF 9.0
Code to reproduce included below:
The text was updated successfully, but these errors were encountered: