Skip to content

Using (i.e. filtering) projected primitive collection down the line fail #35580

Open

Description

@cincuranet

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions