Open
Description
This code fails.
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using (var db = new MyContext())
{
var listOfInt = new List<int> { 1 };
await db.Items.Select((e) => new { e.Id, listOfInt }).Where(x => x.listOfInt.Any()).ToListAsync();
}
class MyContext : DbContext
{
public DbSet<Item> Items { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlite("Data Source=triage.db")
.LogTo(Console.WriteLine, filter: (id, level) => id == RelationalEventId.CommandExecuting)
.EnableSensitiveDataLogging();
}
}
class Item
{
public int Id { get; set; }
public string? Name { get; set; }
}
System.InvalidOperationException: The LINQ expression 'DbSet<Item>()
.Where(i => __listOfInt_0
.Any())' could not be translated. Additional information: Translation of method 'System.Linq.Enumerable.Any' failed. If this method can be mapped to your custom function, see https://go.microsoft.com/fwlink/?linkid=2132413 for more information. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Related to #35579.