-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Did Contains stop working on empty list in EF Core 8? #32375
Comments
@jozseftuska I can't repro this - see the below LINQ query. I need to see an actual code sample here - posting a debug view of a query and a stack trace are not sufficient. Please post a minimal, runnable code sample, or tweak the below sample to make it fail. Attempted repoawait using var ctx = new BlogContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
_ = ctx.Blogs.Where(x => new List<int> { }.Contains(x.Id)).ToList();
public class BlogContext : DbContext
{
public DbSet<Blog> Blogs { 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? Name { get; set; }
} |
I ran into a similar error.
The exception is: |
Dear @roji, thank you for the quick response. Our query is created using AutoMapper based on the documentation. I created a minimal example of the issue: repository Looking forward to your answer. |
Thanks for the repros! I'm currently away but I'll take a look at this next week for sure. |
Minimal repro is any composing on top of an empty inline array: _ = ctx.Blogs.Where(b => new int[] { }.Contains(b.Id)).ToList(); The above query in itself is of course contrived, but people may indeed be creating constant nodes programmatically via the Expression API, and this should translate. Note that this repro doesn't work for List because of #32413. |
Reopening to consider servicing. |
Fixes dotnet#32375 (cherry picked from commit 01a470c)
Question
Did Contains stop working on empty list in EF Core 8?
My database server is Microsoft SQL Server 2017, compatibility level is set to 140. A query that was working before on .NET6 and EF Core 6 is no longer functioning.
Do we need to check now when calling contains if the list is empty?
Code
Edit - Full code: repository
The debug view of the query will look like this:
Stack traces
Provider and version information
EF Core version: 8.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.8
The text was updated successfully, but these errors were encountered: