Required owned entity on a TPH derived type is materialized for an unrelated row
メンテナーはふだん 2 日以内に返信
@AndriySvyryd がすでに取り組んでいます。
2026年7月17日 から。
評価
この issue はまだ評価されていません。
説明
Bug description
Using TPH, a derived type has a required OwnsOne navigation:
efcore-tph-required-owned-repro.zip
modelBuilder.Entity<CircleOverlay>(builder =>
{
builder.OwnsOne(x => x.Shape);
builder.Navigation(x => x.Shape).IsRequired();
});
The database contains only a LineOverlay and no CircleOverlay rows. However,
querying the base type still invokes the Circle constructor with null:
await db.Overlays.AsNoTracking().ToListAsync();
CircleOverlay rows in database: 0
Circle constructor called: point is null = True, radius = 0
System.ArgumentNullException: Value cannot be null. (Parameter 'point')
Expected
EF materializes the LineOverlay without invoking the Circle constructor,
because the row discriminator is LineOverlay.
Reproduction
Run the attached project:
dotnet run
Reproduced with:
- EF Core / SQLite provider 10.0.10
- .NET 10.0
This appears related to #31353, which was fixed in 8.0.3. Unlike that issue,
this owned navigation is explicitly configured as required. Making it optional
avoids the exception, but changes the model semantics: every CircleOverlay
must have a Circle.
Your code
A complete minimal runnable reproduction project is attached:
[EfCoreTphRequiredOwnedRepro.zip](replace-with-the-link-generated-by-GitHub)
Run it with:
dotnet run
Stack traces
Materializing the base TPH query...
Circle constructor called: point is null = True, radius = 0
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'point')
at System.ArgumentNullException.Throw(String paramName)
at System.ArgumentNullException.ThrowIfNull(Object argument, String paramName)
at Circle..ctor(String point, Double radius) in C:\myfiles\mytemp\projects\efcore-tph-required-owned-repro\Program.cs:line 62
at lambda_method84(Closure, QueryContext, DbDataReader, ResultContext, SingleQueryResultCoordinator)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at Program.<Main>$(String[] args) in C:\myfiles\mytemp\projects\efcore-tph-required-owned-repro\Program.cs:line 32
Verbose output
EF Core version
10.0.10
Database provider
Microsoft.EntityFrameworkCore.Sqlite
Target framework
.NET 10
Operating system
No response
IDE
No response
- 主要言語
- C#
- スター
- 14.8k
- フォーク
- 3.4k
- 平均マージ
- 3日 18時間
- マージ済み PR(30日)
- 159
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dotnet/efcore のほかの issue
-
customer-reported
難易度 4/5 3〜5日 初心者へのやさしさ 54/100
メンテナーはふだん 2 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 2 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 2 日以内に返信
-
Regression in 11.0: replacing an owned instance or re-adding an entity with the same key sets unchanged OnAdd properties to null対応中かも @seragAhmed が今日担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
dotnet/efcore#39617 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
customer-reported
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 2 日以内に返信
似ている issue
-
bug emitter:client:csharp
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
microsoft/typespec#12572 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
needs-area-label
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
AWS Lambda: KeyNotFoundException drops HTTP-triggered transactions when allowAllHeaders is disabledオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
newrelic/newrelic-dotnet-agent#3949 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
area-networking
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dotnet/aspnetcore#70545 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 87/100
メンテナーはふだん 1 日以内に返信