Owned JSON collection navigation absent from the stored document materializes as null (owned counterpart of #38625)
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 65/100
調査の方向性
Start with JsonEntityMaterializerRewriter and compare the absent-property fixup from #39014 with the handling of INavigation collections. Use the existing JsonEntityBasic fixture with SQLite and shaped documents to cover absent and explicit-null keys in tracking and no-tracking queries. Done means an absent owned collection materializes as empty while explicit JSON null remains null.
索引モデルが issue の本文から書いたものです。
説明
Bug description
#38625 reports that a complex collection mapped to JSON whose key is absent from the stored document is materialized as null rather than an empty collection, so rows persisted before the collection was added to the type become unusable. #39014 fixes that for complex collections and, on purpose, leaves owned entity collection navigations mapped to JSON alone to keep the change to the reported scenario.
The owned case has exactly the same behavior, from the same code path: JsonEntityMaterializerRewriter runs every nested-property fixup after the read loop, so a navigation that never appeared in the document has its fixup invoked with null.
Reproduced on main with the existing JsonEntityBasic fixture (SQLite, json_remove/json_set to shape the stored document):
Stored OwnedReferenceRoot document |
AsNoTracking() |
tracking |
|---|---|---|
key OwnedCollectionBranch absent |
OwnedCollectionBranch == null |
null |
key present with [] |
empty list | empty list |
So an application that adds an owned collection to an existing JSON-mapped owned type sees null for every pre-existing row, but [] for every row written afterwards. Documents written by EF always contain the key, so this only bites after schema evolution or with documents produced by another writer.
Expected behavior
Consistent with the fix for complex collections in #39014: an absent owned collection navigation materializes as an empty collection; an explicit JSON null is preserved.
Precedent within EF
- Cosmos already does this.
CosmosShapedQueryCompilingExpressionVisitorcreates a nested collection withcollectionAccessor.Create()before its property read loop and adds elements as they are read (source), so a key that never appears yields an empty collection. (Cosmos also yields empty for an explicitnull; the relational fix in #39014 keepsnullthere, which seems the better distinction, but the absent-key outcome is the same.) - Relational already produces the same object for a present
[].MaterializeJsonEntityCollectionbuilds the empty collection through the property'sIClrCollectionAccessor; the fix in #39014 uses the same accessor for the absent case, so absent and[]become indistinguishable, which is what a schema-evolved row needs.
Notes for the fix
The mechanism from #39014 extends directly: register the absent-property fixup for INavigation { IsCollection: true } as well as IComplexProperty. Two details differ from the complex case and are worth a decision:
- Tracking queries. For owned entities the change tracker performs fixup, and the existing tracked fixup only assigns the collection when it is
nullor empty. An absent key should produce the same result as a present[], which the tracked path already assigns, so the absent fixup can assign the empty collection unconditionally. - Behavioral change. Unlike complex collections (new in 10.0), owned JSON collections have materialized
nullfor an absent key since JSON columns shipped in EF 7. Anyone relying onnullhere would see[]instead.
I'm happy to do this either as an extension of #39014 or as a separate PR once that one lands; which would the team prefer?
- 主要言語
- C#
- スター
- 14.8k
- フォーク
- 3.5k
- 平均マージ
- 3日 7時間
- マージ済み PR(30日)
- 182
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dotnet/efcore のほかの issue
-
customer-reported
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
GroupBy element `OrderBy(...).First()`/`MaxBy` over an owned type mapped to its own table fails to translate対応中かも @cincuranet が今日担当しました。 オープンarea-groupby area-query
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
dotnet/efcore#39833 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
SQLite: Polygon.Length translates to GLength, which returns 0対応中かも @cincuranet が今日担当しました。 オープンarea-query area-sqlite
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
dotnet/efcore#39826 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
Migration lock with LockReleaseBehavior.Transaction doesn't prevent concurrent migrations since per-migration transactions対応中かも @AndriySvyryd が 1 日前に担当しました。 オープンarea-migrations
dotnet/efcore#39824 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
Querying a TPC base type with a JSON complex property throws対応中かも @cincuranet が 1 日前に担当しました。 オープンarea-query
難易度 4/5 3〜5日 初心者へのやさしさ 22/100
dotnet/efcore#39814 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
SubtitleEdit/subtitleedit#17247 ·
メンテナーはふだん 1 日以内に返信
-
Restore test cleanup fails on Windows when restored files are read-only対応中かも @JamBalaya56562 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
duplicati/duplicati#8046 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
Bundles Documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
pyrevitlabs/pyRevit#4285 ·
メンテナーはふだん 1 日以内に返信