Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you pass a PartitionKey to Execute a StoredProcedure?

I'm trying to execute a stored procedure on a partitioned collection (server side partitioning) from the .net SDK (v1.6.3).

await client.ExecuteStoredProcedureAsync<string>(UriFactory.CreateStoredProcedureUri("db0", "collection0", "testsproc0"), storedProcedureParams);

I receive the error "PartitionKey value must be supplied for this operation". In fact, I see this error in the Azure Portal when I play around with the Script Explorer. However, I see no way to add a PartitionKey. Is this a limitation with the API and partitioned collections right now, or am I missing something?

like image 209
JamyRyals Avatar asked Apr 21 '16 15:04

JamyRyals


People also ask

What should I use as a partition key?

Use item ID as the partition key One possible example of such a property is the item ID. For small read-heavy containers or write-heavy containers of any size, the item ID is naturally a great choice for the partition key. The system property item ID exists in every item in your container.

What is partition key path?

A partition key consists of a path, like "/firstname", or "/name/first". You can use alphanumeric and underscore characters in the path. The partition key needs to be a JSON property in the documents that you store in the container.

Is partition key mandatory?

It isn't mandatory to explicitly tell cosmos about the partition key (via argument or CosmosItemRequestOptions) during a CRUD operation. If unavailable, cosmos reads the document (which is being added/updated) and finds the partition key.


1 Answers

you can pass in the partition key by using the overloaded ExecuteStoredProcedureAsync method with RequestOptions. For example,

await client.ExecuteStoredProcedureAsync<DeviceSignal>(
UriFactory.CreateStoredProcedureUri("db", "coll", "SetLatestStateAcrossReadings"),
new RequestOptions { PartitionKey = new PartitionKey("XMS-001") }, sprocsParams);
like image 157
h0n Avatar answered Oct 20 '22 05:10

h0n