-
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
Exception on query comparing nullable int with ?? fallback on EF Core 9 #35095
Comments
Confirmed regression from EF8 to 9. |
I hit this too updating to EfCore 9.0.0. Is there a workaround or will the fix be in 9.0.1? |
@Steve887 Depending on your query it seems you can un-confuse the Expression checking. E.g. this works:
|
The problem here is the funcletizer's simplification of the binary expression Runnable reproawait using var context = new BlogContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
int? test = 1;
var blog = context.Blogs.Where(b => b.Id == (test ?? 0)).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; }
} |
Don't know whether this is related, but we are experiencing nullable-related exceptions also when translating queries like this: The fallback value for nullable seems to be ignored. // param
Guid? scopeId = null;
Guid defaultScopeId = some_value;
// Cannot be translated. Scopes.Id is a list of `Guid`.
entities.Where(e => e.Scopes.Select(s => s.Id).Contains(scopeId ?? defaultScopeId)); Throws:
|
Is this the same as this error? I get it while trying to generate a
This used to work in many previous versions of EF Core |
File a bug
When comparing a nullable integer that has a ?? fallback an exception occurs at query time.
Include your code
In the get started sample add the following
Notice that there is no error with the PackageReference to Microsoft.EntityFrameworkCore.Sqlite:8.0
now switch to 9.0, rebuild => Exception
Include stack traces
Include provider and version information
EF Core version: 9.0
Database provider: multiple (teste on SqlLite and Sql)
Target framework: net9 and net8
Operating system: Windows
IDE: On all
The text was updated successfully, but these errors were encountered: