-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why can't a CosmosDB partition key be an int when working with EF Core? #28265
Labels
area-cosmos
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-enhancement
Milestone
Comments
use this to avoid the error .HasConversion() |
If I understand correctly, .HasConversion() will allow me to work with an integer type in my code, but will still require the underlying type in the document to be a string. I'd like to have the underlying type be an integer, which .HasConversion() doesn't solve. |
ajcvickers
added a commit
that referenced
this issue
May 1, 2024
Fixes #28186 Fixes #28265 Fixes #33535 Also: - Allow non-string partition key values - Warn if no partition key has been defined - Use a value converter if needed for values passed to WithPartitionKey (This is probably a bug, but should be docced as a breaking change anyway.) Updated based on review feedback
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-cosmos
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-enhancement
Ask a question
As you can see here:
efcore/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs
Lines 313 to 318 in 4a2e4eb
EF Core Cosmos provider seems to force that a partition key be a string (or have a value converter to map to a string). But CosmosDB itself does not seem to have this restriction. According to: https://docs.microsoft.com/en-us/azure/cosmos-db/partitioning-overview :
"The partition key value can be of string or numeric types."
I've confirmed that I can successfully use int as a Cosmos DB document partition key type (when EF Core is not in the picture). But Cosmos seems to throw the exception outlined in the above github link whenever you use WithPartitionKey for the relevant document:
It seems like I should be able to specify an integer partition key when using EF Core with Cosmos DB. Am I mistaken?
Include provider and version information
EF Core version: 6.0.6
Database provider: (e.g. Microsoft.EntityFrameworkCore.Cosmos)
Target framework: (e.g. .NET 6.0)
Operating system:
IDE: (e.g. Visual Studio 2022 17.2.4)
The text was updated successfully, but these errors were encountered: