Allow referencing the outside entity in filtered include
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
We don't translate filtered includes when the outside entity is referenced (`b` in the below code):
```c#
_ = await context.Blogs
.Include(b => b.Posts.Where(p => p.Foo == b.Foo))
.ToListAsync();
```
This should be translatable as a lateral join/cross apply.
A workaround is to flip the query around:
```c#
_ = await context.Blogs
.Include(b => b.Posts.Where(p => p.Foo == b.Foo))
.ToListAsync();
```
Full repro
```c#
await using var context = new BlogContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
_ = await context.Blogs
.Include(b => b.Posts.Where(p => p.Foo == b.Foo))
.ToListAsync();
public class BlogContext : DbContext
{
public DbSet Blogs { get; set; }
public DbSet Posts { 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 Blog
{
public int Id { get; set; }
public string Foo { get; set; }
public List Posts { get; set; }
}
public class Post
{
public int Id { get; set; }
public string Foo { get; set; }
public Blog Blog { get; set; }
}
```
Raised by @atrauzzi in https://github.com/npgsql/efcore.pg/issues/3118
Contributor guide
Assessment
This issue has not been assessed yet.