Skip to content
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

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

Open
cincuranet opened this issue Feb 4, 2025 · 0 comments
Open

Comments

@cincuranet
Copy link
Contributor

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
Projects
None yet
Development

No branches or pull requests

2 participants