From 045c5498f571a52d6cddd3d57ac5e9f6aed6322d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 11:41:49 +0000 Subject: [PATCH 1/6] Initial plan From 6b30844f79810e997461fe48972e4b5e6401746e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 11:50:54 +0000 Subject: [PATCH 2/6] Document Cosmos support for complex types Document https://github.com/dotnet/efcore/issues/31253 Co-authored-by: roji <1862641+roji@users.noreply.github.com> --- .../core/providers/cosmos/modeling.md | 78 ++++++++++++++++++- .../core/what-is-new/ef-core-11.0/whatsnew.md | 16 ++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/entity-framework/core/providers/cosmos/modeling.md b/entity-framework/core/providers/cosmos/modeling.md index c3c5262536..3121f2525c 100644 --- a/entity-framework/core/providers/cosmos/modeling.md +++ b/entity-framework/core/providers/cosmos/modeling.md @@ -2,7 +2,7 @@ title: Modeling - Azure Cosmos DB Provider - EF Core description: Configuring the model with the Azure Cosmos DB EF Core Provider author: roji -ms.date: 09/26/2024 +ms.date: 03/18/2026 uid: core/providers/cosmos/modeling --- # Configuring the model with the EF Core Azure Cosmos DB Provider @@ -325,6 +325,82 @@ Limitations: * Only dictionaries with string keys are supported. * Support for querying into primitive collections was added in EF Core 9.0. +## Complex types + +> [!NOTE] +> This feature is being introduced in EF Core 11, which is currently in preview. + +EF Core [complex types](xref:core/what-is-new/ef-core-10.0/whatsnew#complex-types) are fully supported with the Azure Cosmos DB provider. Like owned entities, complex types are embedded as nested JSON objects within the document of the owning entity. For example, consider the following model: + +```csharp +public class Order +{ + public int Id { get; set; } + public required ShippingAddress ShippingAddress { get; set; } +} + +[ComplexType] +public class ShippingAddress +{ + public required string Street { get; set; } + public required string City { get; set; } + public required string PostalCode { get; set; } +} +``` + +When saving an `Order`, EF embeds the `ShippingAddress` complex type as a nested JSON object: + +```json +{ + "Id": 1, + "ShippingAddress": { + "Street": "221 B Baker St", + "City": "London", + "PostalCode": "NW1 6XE" + } +} +``` + +The JSON property name used for the complex type can be customized using : + +```csharp +modelBuilder.Entity() + .ComplexProperty(o => o.ShippingAddress, b => b.ToJsonProperty("Address")); +``` + +Collections of complex types are also supported and are embedded as JSON arrays: + +```csharp +public class Order +{ + public int Id { get; set; } + public List Lines { get; set; } = []; +} + +[ComplexType] +public class OrderLine +{ + public required string ProductName { get; set; } + public int Quantity { get; set; } +} +``` + +This results in the following JSON structure: + +```json +{ + "Id": 1, + "Lines": [ + { "ProductName": "Widget", "Quantity": 2 }, + { "ProductName": "Gadget", "Quantity": 1 } + ] +} +``` + +The JSON array property name can similarly be customized using `ToJsonProperty()` on the complex collection builder. + +This feature was contributed by [@JoasE](https://github.com/JoasE) - many thanks! + ## Optimistic concurrency with eTags To configure an entity type to use [optimistic concurrency](xref:core/saving/concurrency) call . This call will create an `_etag` property in [shadow state](xref:core/modeling/shadow-properties) and set it as the concurrency token. diff --git a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md index a6c8aa1b4c..0d32e8bbfb 100644 --- a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md +++ b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md @@ -77,6 +77,12 @@ This enhancement removes a significant limitation when modeling complex domain h For more information on inheritance mapping strategies, see [Inheritance](xref:core/modeling/inheritance). + + +### Complex types in Azure Cosmos DB + +Complex types are now fully supported in the Azure Cosmos DB provider, embedded as nested JSON objects or arrays. For more information, [see the Cosmos DB documentation](xref:core/providers/cosmos/modeling#complex-types). + ## LINQ and SQL translation @@ -106,6 +112,16 @@ Similarly, `MinByAsync` orders ascending and returns the element with the minimu ## Cosmos DB + + +### Complex types + +EF Core [complex types](xref:core/what-is-new/ef-core-10.0/whatsnew#complex-types) are now fully supported in the Azure Cosmos DB provider; they are embedded as nested JSON objects (or arrays, for collections) within the owning document, with support for queries, inserts, and updates. + +For more information, [see the documentation](xref:core/providers/cosmos/modeling#complex-types). + +This feature was contributed by [@JoasE](https://github.com/JoasE) - many thanks! + ### Transactional batches From 8520e151e78f5b39598890845f249b1e87f23555 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 17:27:58 +0000 Subject: [PATCH 3/6] Remove complex types section from modeling.md; update what's new links - Remove the ## Complex types section from cosmos/modeling.md (full docs will be added later) - Update the one-liner in ## Complex types to link to the Cosmos what's new section instead of modeling page - Remove the dead link to modeling page from the Cosmos ## Complex types what's new entry Co-authored-by: roji <1862641+roji@users.noreply.github.com> --- .../core/providers/cosmos/modeling.md | 76 ------------------- .../core/what-is-new/ef-core-11.0/whatsnew.md | 4 +- 2 files changed, 1 insertion(+), 79 deletions(-) diff --git a/entity-framework/core/providers/cosmos/modeling.md b/entity-framework/core/providers/cosmos/modeling.md index 3121f2525c..ee58102015 100644 --- a/entity-framework/core/providers/cosmos/modeling.md +++ b/entity-framework/core/providers/cosmos/modeling.md @@ -325,82 +325,6 @@ Limitations: * Only dictionaries with string keys are supported. * Support for querying into primitive collections was added in EF Core 9.0. -## Complex types - -> [!NOTE] -> This feature is being introduced in EF Core 11, which is currently in preview. - -EF Core [complex types](xref:core/what-is-new/ef-core-10.0/whatsnew#complex-types) are fully supported with the Azure Cosmos DB provider. Like owned entities, complex types are embedded as nested JSON objects within the document of the owning entity. For example, consider the following model: - -```csharp -public class Order -{ - public int Id { get; set; } - public required ShippingAddress ShippingAddress { get; set; } -} - -[ComplexType] -public class ShippingAddress -{ - public required string Street { get; set; } - public required string City { get; set; } - public required string PostalCode { get; set; } -} -``` - -When saving an `Order`, EF embeds the `ShippingAddress` complex type as a nested JSON object: - -```json -{ - "Id": 1, - "ShippingAddress": { - "Street": "221 B Baker St", - "City": "London", - "PostalCode": "NW1 6XE" - } -} -``` - -The JSON property name used for the complex type can be customized using : - -```csharp -modelBuilder.Entity() - .ComplexProperty(o => o.ShippingAddress, b => b.ToJsonProperty("Address")); -``` - -Collections of complex types are also supported and are embedded as JSON arrays: - -```csharp -public class Order -{ - public int Id { get; set; } - public List Lines { get; set; } = []; -} - -[ComplexType] -public class OrderLine -{ - public required string ProductName { get; set; } - public int Quantity { get; set; } -} -``` - -This results in the following JSON structure: - -```json -{ - "Id": 1, - "Lines": [ - { "ProductName": "Widget", "Quantity": 2 }, - { "ProductName": "Gadget", "Quantity": 1 } - ] -} -``` - -The JSON array property name can similarly be customized using `ToJsonProperty()` on the complex collection builder. - -This feature was contributed by [@JoasE](https://github.com/JoasE) - many thanks! - ## Optimistic concurrency with eTags To configure an entity type to use [optimistic concurrency](xref:core/saving/concurrency) call . This call will create an `_etag` property in [shadow state](xref:core/modeling/shadow-properties) and set it as the concurrency token. diff --git a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md index 0d32e8bbfb..b6857d6de5 100644 --- a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md +++ b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md @@ -81,7 +81,7 @@ For more information on inheritance mapping strategies, see [Inheritance](xref:c ### Complex types in Azure Cosmos DB -Complex types are now fully supported in the Azure Cosmos DB provider, embedded as nested JSON objects or arrays. For more information, [see the Cosmos DB documentation](xref:core/providers/cosmos/modeling#complex-types). +Complex types are now fully supported in the Azure Cosmos DB provider, embedded as nested JSON objects or arrays. For more information, [see the Cosmos DB section below](#cosmos-complex-types). ## LINQ and SQL translation @@ -118,8 +118,6 @@ Similarly, `MinByAsync` orders ascending and returns the element with the minimu EF Core [complex types](xref:core/what-is-new/ef-core-10.0/whatsnew#complex-types) are now fully supported in the Azure Cosmos DB provider; they are embedded as nested JSON objects (or arrays, for collections) within the owning document, with support for queries, inserts, and updates. -For more information, [see the documentation](xref:core/providers/cosmos/modeling#complex-types). - This feature was contributed by [@JoasE](https://github.com/JoasE) - many thanks! From 0cda415b189c7b89cf892270b3c7083169da9db8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 17:31:39 +0000 Subject: [PATCH 4/6] Add minimal code sample to Cosmos complex types what's new entry Co-authored-by: roji <1862641+roji@users.noreply.github.com> --- .../core/what-is-new/ef-core-11.0/whatsnew.md | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md index b6857d6de5..d5b6dfa05c 100644 --- a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md +++ b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md @@ -118,6 +118,35 @@ Similarly, `MinByAsync` orders ascending and returns the element with the minimu EF Core [complex types](xref:core/what-is-new/ef-core-10.0/whatsnew#complex-types) are now fully supported in the Azure Cosmos DB provider; they are embedded as nested JSON objects (or arrays, for collections) within the owning document, with support for queries, inserts, and updates. +For example, given the following model: + +```csharp +public class Order +{ + public int Id { get; set; } + public required ShippingAddress ShippingAddress { get; set; } +} + +[ComplexType] +public class ShippingAddress +{ + public required string Street { get; set; } + public required string City { get; set; } +} +``` + +EF will embed the `ShippingAddress` as a nested JSON object in the `Order` document: + +```json +{ + "id": 1, + "ShippingAddress": { + "Street": "221 B Baker St", + "City": "London" + } +} +``` + This feature was contributed by [@JoasE](https://github.com/JoasE) - many thanks! From ce72a45bdb143ed7e68bdc245da195aa8d7ed33b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 17:37:48 +0000 Subject: [PATCH 5/6] Replace attribute-only code sample with Fluent API/Data Annotations tabs; remove JSON sample Co-authored-by: roji <1862641+roji@users.noreply.github.com> --- .../core/what-is-new/ef-core-11.0/whatsnew.md | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md index d5b6dfa05c..acafa9f35a 100644 --- a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md +++ b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md @@ -118,15 +118,18 @@ Similarly, `MinByAsync` orders ascending and returns the element with the minimu EF Core [complex types](xref:core/what-is-new/ef-core-10.0/whatsnew#complex-types) are now fully supported in the Azure Cosmos DB provider; they are embedded as nested JSON objects (or arrays, for collections) within the owning document, with support for queries, inserts, and updates. -For example, given the following model: +For example, the following configures `ShippingAddress` as a complex type: + +### [Fluent API](#tab/fluent-api) ```csharp -public class Order -{ - public int Id { get; set; } - public required ShippingAddress ShippingAddress { get; set; } -} +modelBuilder.Entity() + .ComplexProperty(o => o.ShippingAddress); +``` +### [Data Annotations](#tab/data-annotations) + +```csharp [ComplexType] public class ShippingAddress { @@ -135,17 +138,9 @@ public class ShippingAddress } ``` -EF will embed the `ShippingAddress` as a nested JSON object in the `Order` document: +*** -```json -{ - "id": 1, - "ShippingAddress": { - "Street": "221 B Baker St", - "City": "London" - } -} -``` +Complex types are generally a better fit than owned types when mapping to JSON documents: unlike owned types, complex types have value semantics and no identity, which means they work better in scenarios such as comparing two embedded objects within the same document, or using them as keys. This feature was contributed by [@JoasE](https://github.com/JoasE) - many thanks! From f2e6636e86e220b2b099c69c005cf4a7d8289a71 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 06:42:18 +0000 Subject: [PATCH 6/6] Fix tab heading levels to ####, remove ambiguous 'keys' phrasing, revert modeling.md ms.date Co-authored-by: roji <1862641+roji@users.noreply.github.com> --- entity-framework/core/providers/cosmos/modeling.md | 2 +- entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/entity-framework/core/providers/cosmos/modeling.md b/entity-framework/core/providers/cosmos/modeling.md index ee58102015..c3c5262536 100644 --- a/entity-framework/core/providers/cosmos/modeling.md +++ b/entity-framework/core/providers/cosmos/modeling.md @@ -2,7 +2,7 @@ title: Modeling - Azure Cosmos DB Provider - EF Core description: Configuring the model with the Azure Cosmos DB EF Core Provider author: roji -ms.date: 03/18/2026 +ms.date: 09/26/2024 uid: core/providers/cosmos/modeling --- # Configuring the model with the EF Core Azure Cosmos DB Provider diff --git a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md index acafa9f35a..6842144aeb 100644 --- a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md +++ b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md @@ -120,14 +120,14 @@ EF Core [complex types](xref:core/what-is-new/ef-core-10.0/whatsnew#complex-type For example, the following configures `ShippingAddress` as a complex type: -### [Fluent API](#tab/fluent-api) +#### [Fluent API](#tab/fluent-api) ```csharp modelBuilder.Entity() .ComplexProperty(o => o.ShippingAddress); ``` -### [Data Annotations](#tab/data-annotations) +#### [Data Annotations](#tab/data-annotations) ```csharp [ComplexType] @@ -140,7 +140,7 @@ public class ShippingAddress *** -Complex types are generally a better fit than owned types when mapping to JSON documents: unlike owned types, complex types have value semantics and no identity, which means they work better in scenarios such as comparing two embedded objects within the same document, or using them as keys. +Complex types are generally a better fit than owned types when mapping to JSON documents: unlike owned types, complex types have value semantics and no identity, which means they work better in scenarios such as comparing two embedded objects within the same document. This feature was contributed by [@JoasE](https://github.com/JoasE) - many thanks!