Closed 2xRon closed 1 month ago
EF can't know beforehand that a given navigation will be null
when loaded. In a situation like this you can supply this information manually:
if (command.CommandExtensionTypeId == null)
{
context.Entry(command).Reference(c => c.CommandExtensionType).IsLoaded = true;
}
File a bug
Setup:
Include your code
Reproduction
Context
Include provider and version information
EF Core version: Database provider: can replicate in Microsoft.EntityFrameworkCore.SqlServer and Sqlite Target framework: can replicate in .NET 8.0 and .NET 7.0 Operating system: Windows 11 IDE: Visual Studio 2022 17.4
NullLazyLoadTest.zip
Possible Resolution
For now we're thinking of replacing the LazyLoader with an identical implementation except for replacing ShouldLoad with
Though I'm sure there is a better way to accomplish this.