question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Misleading parameter PartitionKey in methods ReadItemStreamAsync and ReadItemAsync?

See original GitHub issue

Hi there,

ReadItemStreamAsync and ReadItemAsync both expect a parameter PartitionKey partitionKey.

It requires to provide the value of the partition key, not the name of the the partition key.

I find this confusing because e.g. on the storage explorer and data explorer the term partionkey refers to the name of the key and not the value.

Maybe the name of the parameter can be adjusted to reflect that it is the value that should be passed in.

What is more, why do I have to create a partionkey object in the first place? Wouldn’t it be easier to pass a string as parameter for the partitionkeyvalue and create the object internally?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
j82wcommented, Sep 12, 2019

In the v3 SDK it is required to always provide a partition key path. In v2 it is optional. The problem is that people where creating non-partitioned containers. Their apps and data would grow to the point that it would hit the cap. Once a container is created the partition key path can not be changed. This requires users to create a new partitioned container, and migrate all the data. This is a very painful process. To avoid this scenario all the new SDKs always make the container partitioned. The PartitionKey.None is used to allow access in the older non-partitioned containers.

If you are sure that your data will not need to scale you could define a new field like ‘/pk’ as the partition key path. Then just have it always hard coded to string.Empty. That way you know that read will always be partition key value of string.empty. Then in the future if you find you do need to scale you can start populating that field with a real partition key value.

2reactions
bartelinkcommented, Sep 12, 2019

Just Explicit is better than Implicit rule in general. For important stuff like the partition key spec, Making Me Think a little bit is a good thing. i.e. being forced to write new PartionKeyValue(key) versus some magic doing that for me means (in this strawman example) a) extra allocations b) I dont recognize that this might be something I want to have a strong type for c) I don’t get to see that PartionKeyValue can also be constructed with an int

Implicit operators for me need to be a) really high traffic b) really improve readability for common cases. I think XLinq uses them and was a good design (perhaps someone who has dealt with feedback 2 years down the road might disagree)

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# Cosmos DB ReadItemAsync Partition Key multiple values
I am calling a function that uses ReadItemAsync to return a single document from the container. I'd like to include the Partition Key...
Read more >
Read an item in Azure Cosmos DB for NoSQL using .NET
To perform a point read of an item, call one of the following methods: ReadItemAsync<>; ReadItemStreamAsync<>; ReadManyItemsAsync<> ...
Read more >
Persisting Cloud Events to Cosmos DB in Azure
We'll need to change the PartitionKeyPath to be /partitionKey instead of /type. Unfortunately this means you'll need to recreate the container ( ...
Read more >
Untitled
2019 · Misleading parameter PartitionKey in methods ReadItemStreamAsync and ReadItemAsync? · Issue #795 · Azure/azure-cosmos-dotnet-v3 · GitHub Azure ...
Read more >
C# (CSharp) ItemResponse Examples
Resource.Id, teamResponse.RequestCharge); //ItemResponse<Team> andersenFamilyResponse = await container.ReadItemAsync<Team>(t.Id, new PartitionKey(t.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found