Document Cosmos DB id mapping changes in EF Core 9.0 and add SDK migration scripts#5414
Open
AndriySvyryd with Copilot wants to merge 6 commits into
Open
Document Cosmos DB id mapping changes in EF Core 9.0 and add SDK migration scripts#5414AndriySvyryd with Copilot wants to merge 6 commits into
AndriySvyryd with Copilot wants to merge 6 commits into
Conversation
….md and migration code to breaking-changes.md
Copilot
AI
changed the title
[WIP] Document Cosmos id mapping changes in 9.0 with breaking change note
Document Cosmos DB id mapping changes in EF Core 9.0 and add SDK migration scripts
Jul 3, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates EF Core 9.0 Cosmos DB documentation to explain the new id/key mapping behavior and adds Azure Cosmos DB SDK migration snippets to help users update existing documents to the new defaults.
Changes:
- Document EF Core 9.0’s Cosmos
idmapping (key maps directly to JSONid) and introduce guidance for shadowidusage. - Add Cosmos SDK migration examples for renaming
Discriminator→$type, rewritingidvalues, and removing redundant key properties.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| entity-framework/core/what-is-new/ef-core-9.0/breaking-changes.md | Adds Cosmos SDK-based migration snippets for EF Core 9.0 Cosmos breaking changes. |
| entity-framework/core/providers/cosmos/modeling.md | Updates Cosmos modeling docs to describe EF Core 9.0 key/id mapping and shadow id behavior. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines
+454
to
+457
| if (item.ContainsKey("Discriminator")) | ||
| { | ||
| item["$type"] = item["Discriminator"]!.DeepClone(); | ||
| item.Remove("Discriminator"); |
Comment on lines
30
to
+32
| Azure Cosmos DB requires all documents to have an `id` JSON property which uniquely identifies them. Like other EF providers, the EF Azure Cosmos DB provider will attempt to find a property named `Id` or `<type name>Id`, and configure that property as the key of your entity type, mapping it to the `id` JSON property. You can configure any property to be the key property by using <xref:Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder`1.HasKey*>; see [the general EF documentation on keys](xref:core/modeling/keys) for more information. | ||
|
|
||
| Starting with EF 9.0, the entity's key property is directly mapped to the JSON `id` property — they are one and the same property in the document. This means the key value is not stored twice. For example, a `Blog` entity with `Id = 8` produces a document where the `id` property contains the string value `"8"`: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4883
Fixes #4821
EF Core 9.0 changed how the Azure Cosmos DB provider maps entity keys to the JSON
idproperty and removed the discriminator fromidby default. This PR adds documentation for those changes and provides Azure Cosmos DB SDK code samples to migrate existing documents.modeling.md— IDs and keys sectionid(no duplicate storage)id, and how to opt in explicitly viaHasShadowId()/HasShadowIds()breaking-changes.md— Migration code samplesAdds SDK-based migration code for each breaking change, for users who want to adopt the new defaults rather than revert:
Rename
Discriminator→$type(non-breakingReplaceItemAsync):Strip discriminator prefix from
id(requires delete + re-create since Cosmos DB prohibitsidupdates):Remove redundant key property (now that
idand the key property are the same):Each sample includes notes on partition key configuration and idempotency considerations for the delete+re-create pattern.