Constructor calls when using inheritance with owned entities causes exceptions #31353
Labels
area-query
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
Milestone
Description and Code
When using owned entities it is fairly normal to use some sort of constructor validation, like throwing
ArgumentNullException
for null values.When an owned type like this is used in an inheritance hierarchy on a child EfCore tries to call the constructor with null values for some reason when the parent DbSet is queried. This then leads to a
ArgumentNullException
.This only happens when entities of another type that actually have
NULL
values in their columns are also present in the table.Repro
A repo for the problem can be found here: https://github.com/Jejuni/EfCoreInheritanceProblem
Replace the SqlServer connection string in
MyDbContext
with a valid one for your machine.Code
Given these entities:
and this configuration:
leads to an exception when the following code is run:
Include stack traces
Stack trace shows the code thrown from user error during execution of
SingleQueryingEnumerable
:Include provider and version information
EF Core version:
Database provider: Microsoft.EntityFrameworkCore.SqlServer, 7.0.9
Target framework: .NET 7.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.6.5
The text was updated successfully, but these errors were encountered: