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

Comparing DbSet<T>/IQueryable<T> to null in query fails #35598

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

Comparing DbSet<T>/IQueryable<T> to null in query fails #35598

cincuranet opened this issue Feb 7, 2025 · 0 comments
Assignees
Milestone

Comments

@cincuranet
Copy link
Contributor

Bug description

The code is intentionally simple, the ids could be conditionally selected.

Works fine in 8.

Your code

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;

using var db = new MyContext();
var ids = db.Items.Select(c => c.Id);
db.Items.Where(r => ids != null && ids.Contains(r.Id)).Load();

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; }
}

Stack traces

The LINQ expression 'DbSet<Item>()
    .Where(i => DbSet<Item>()
        .Select(i0 => i0.Id) != null && DbSet<Item>()
        .Select(i1 => i1.Id)
        .Contains(i.Id))' could not be translated.

Verbose output


EF Core version

9.0.1

Database provider

N/A

Target framework

net9.0

Operating system

N/A

IDE

N/A

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

1 participant