You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider a related entity loading strategy that aggregates dependent collections to a JSON array #30958
In EF Core 7.0, we're adding type mapping APIs to precisely control how values are serialized/deserialized from JSON; this should allow us to represent any (primitive) value in JSON and reliably serialize/deserialize it to stored documents in the database.
Databases also allow aggregating multiple rows into a single JSON document. On most databases, this is done using an aggregate method (jsonb_agg on PostgreSQL, json_group_array and json_object on SQLite, JSON_ARRAYAGG on MySQL); we added support for custom provider aggregate methods in EF 7.0 as well (#22957). On SQL Server this is done via the special FOR JSON construct.
Combining these features, we could load a related collection navigation by aggregating it to a single JSON text, and deserialize it back on the client. This works around the cartesian explosion and data duplication problems inherent in single queries with JOINs, but also doesn't suffer from the problems of split queries (increased memory needs due to buffering of the principal results, loss of transactional consistency).
On PostgreSQL we'd aggregate to an array instead (no JSON needed; tracked by npgsql/efcore.pg#1691).
Reacted by YohanS, Bruno Martinez, James Chapman, Graham Scanlon, a-ch-chu, David Roth, Michael Messer, Greg Bachraty, Travis Williamson, Willem-Derk Nijdam and 1 more
changed the title [-]Consider a related entity loading strategy that uses aggregates dependent collections to a JSON array[/-][+]Consider a related entity loading strategy that aggregates dependent collections to a JSON array[/+]on May 24, 2023
Note: the same concept can be used for translating final GroupBy without Select: the groups can be aggregated to JSON arrays, transferred to the client and the JSON parsed by EF.
Activity
[-]Consider a related entity loading strategy that uses aggregates dependent collections to a JSON array[/-][+]Consider a related entity loading strategy that aggregates dependent collections to a JSON array[/+]roji commentedon Apr 27, 2024
Note: the same concept can be used for translating final GroupBy without Select: the groups can be aggregated to JSON arrays, transferred to the client and the JSON parsed by EF.