Ask a question
As you can see here:
|
if (partitionKeyType != typeof(string)) |
|
{ |
|
throw new InvalidOperationException( |
|
CosmosStrings.PartitionKeyNonStringStoreType( |
|
partitionKeyPropertyName, entityType.DisplayName(), partitionKeyType.ShortDisplayName())); |
|
} |
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:
"System.InvalidOperationException: 'The type of the partition key property [property] on [document] is 'int'. All partition key properties need to be strings or have a string value converter.'"
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)
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)