-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Open
Description
Bug description
Precompiled query code can have nullable annotations:
public static TSource? Query1_FirstOrDefault1<TSource>(this global::System.Linq.IQueryable<TSource> source)
Building it leads to a warning:
/workspaces/ef-play/nullwarn/Generated/Program.EFInterceptors.Context.cs(32,30): warning CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.
It seems the only way to ignore this warning is to disable it for the whole project.
See attached project with minimal example.
Can be reproduced with:
dotnet ef dbcontext optimize --output-dir Generated --precompile-queries --nativeaot --verbose
> dotnet build
Your code
--- Model.cs
public class Blog
{
public int Id { get; set; }
}
--- Context.cs
using Microsoft.EntityFrameworkCore;
public class Context : DbContext
{
public DbSet<Blog> Blogs { get; set; } = null!;
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.UseSqlite("Data Source=tmp.db");
}
}
--- Program.cs
using var context = new Context();
_ = context.Blogs.FirstOrDefault();Stack traces
Verbose output
EF Core version
10.0.3, 11.0.0-preview.2.26159.112
Database provider
Microsoft.EntityFrameworkCore.Sqlite
Target framework
.NET 10, .NET 11
Operating system
Ubuntu 24.04.4 LTS
IDE
No response
Reactions are currently unavailable