1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . Threading . Tasks ;
44using Microsoft . Azure . Cosmos ;
@@ -194,12 +194,11 @@ public static async Task QueryCustomer()
194194
195195 FeedIterator < CustomerV2 > resultSet = container . GetItemQueryIterator < CustomerV2 > (
196196 new QueryDefinition ( sql )
197- . WithParameter ( "@id" , customerId )
198- //,requestOptions: new QueryRequestOptions()
199- //{
200- // PartitionKey = new PartitionKey(customerId)
201- //}
202- ) ;
197+ . WithParameter ( "@id" , customerId ) ,
198+ requestOptions : new QueryRequestOptions ( )
199+ {
200+ PartitionKey = new PartitionKey ( customerId )
201+ } ) ;
203202
204203 Console . WriteLine ( "Query for a single customer\n " ) ;
205204 while ( resultSet . HasMoreResults )
@@ -228,9 +227,8 @@ public static async Task GetCustomer()
228227
229228 //Get a customer with a point read
230229 ItemResponse < CustomerV2 > response = await container . ReadItemAsync < CustomerV2 > (
231- id : customerId
232- //,partitionKey: new PartitionKey(customerId)
233- ) ;
230+ id : customerId ,
231+ partitionKey : new PartitionKey ( customerId ) ) ;
234232
235233 Print ( response . Resource ) ;
236234
@@ -248,12 +246,11 @@ public static async Task ListAllProductCategories()
248246 string sql = $ "SELECT * FROM c WHERE c.type = 'category'";
249247
250248 FeedIterator < ProductCategory > resultSet = container . GetItemQueryIterator < ProductCategory > (
251- new QueryDefinition ( sql )
252- //,requestOptions: new QueryRequestOptions()
253- //{
254- // PartitionKey = new PartitionKey("category")
255- //}
256- ) ;
249+ new QueryDefinition ( sql ) ,
250+ requestOptions : new QueryRequestOptions ( )
251+ {
252+ PartitionKey = new PartitionKey ( "category" )
253+ } ) ;
257254
258255 while ( resultSet . HasMoreResults )
259256 {
@@ -283,12 +280,11 @@ public static async Task QueryProductsByCategoryId()
283280
284281 FeedIterator < Product > resultSet = container . GetItemQueryIterator < Product > (
285282 new QueryDefinition ( sql )
286- . WithParameter ( "@categoryId" , categoryId )
287- //,requestOptions: new QueryRequestOptions()
288- //{
289- // PartitionKey = new PartitionKey(categoryId)
290- //}
291- ) ;
283+ . WithParameter ( "@categoryId" , categoryId ) ,
284+ requestOptions : new QueryRequestOptions ( )
285+ {
286+ PartitionKey = new PartitionKey ( categoryId )
287+ } ) ;
292288
293289 while ( resultSet . HasMoreResults )
294290 {
@@ -319,12 +315,11 @@ public static async Task QueryProductsForCategory()
319315 "GROUP BY c.categoryName" ;
320316
321317 FeedIterator < dynamic > resultSet = container . GetItemQueryIterator < dynamic > (
322- new QueryDefinition ( sql )
323- //,requestOptions: new QueryRequestOptions
324- //{
325- // PartitionKey = new PartitionKey(categoryId)
326- //}
327- ) ;
318+ new QueryDefinition ( sql ) ,
319+ requestOptions : new QueryRequestOptions
320+ {
321+ PartitionKey = new PartitionKey ( categoryId )
322+ } ) ;
328323
329324 Console . WriteLine ( "Print out category name and number of products in that category\n " ) ;
330325 while ( resultSet . HasMoreResults )
@@ -356,7 +351,7 @@ public static async Task UpdateProductCategory()
356351 } ;
357352
358353 await container . ReplaceItemAsync (
359- // partitionKey: new PartitionKey("category"),
354+ partitionKey : new PartitionKey ( "category" ) ,
360355 id : categoryId ,
361356 item : updatedProductCategory ) ;
362357
@@ -379,7 +374,7 @@ public static async Task RevertProductCategory()
379374 Console . WriteLine ( "Change category name back to original" ) ;
380375
381376 await container . ReplaceItemAsync (
382- // partitionKey: new PartitionKey("category"),
377+ partitionKey : new PartitionKey ( "category" ) ,
383378 id : categoryId ,
384379 item : updatedProductCategory ) ;
385380
@@ -398,12 +393,11 @@ public static async Task QuerySalesOrdersByCustomerId()
398393
399394 FeedIterator < SalesOrder > resultSet = container . GetItemQueryIterator < SalesOrder > (
400395 new QueryDefinition ( sql )
401- . WithParameter ( "@customerId" , customerId )
402- //,requestOptions: new QueryRequestOptions
403- //{
404- // PartitionKey = new PartitionKey(customerId)
405- //}
406- ) ;
396+ . WithParameter ( "@customerId" , customerId ) ,
397+ requestOptions : new QueryRequestOptions
398+ {
399+ PartitionKey = new PartitionKey ( customerId )
400+ } ) ;
407401
408402 Console . WriteLine ( "Print out orders for this customer\n " ) ;
409403 while ( resultSet . HasMoreResults )
@@ -430,12 +424,11 @@ public static async Task QueryCustomerAndSalesOrdersByCustomerId()
430424
431425 FeedIterator < dynamic > resultSet = container . GetItemQueryIterator < dynamic > (
432426 new QueryDefinition ( sql )
433- . WithParameter ( "@customerId" , customerId )
434- //,requestOptions: new QueryRequestOptions
435- //{
436- // PartitionKey = new PartitionKey(customerId)
437- //}
438- ) ;
427+ . WithParameter ( "@customerId" , customerId ) ,
428+ requestOptions : new QueryRequestOptions
429+ {
430+ PartitionKey = new PartitionKey ( customerId )
431+ } ) ;
439432
440433 CustomerV4 customer = new CustomerV4 ( ) ;
441434 List < SalesOrder > orders = new List < SalesOrder > ( ) ;
@@ -482,8 +475,8 @@ public static async Task CreateNewOrderAndUpdateCustomerOrderTotal()
482475 string customerId = "FFD0DD37-1F0E-4E2E-8FAC-EAF45B0E9447" ;
483476 //Get the customer
484477 ItemResponse < CustomerV4 > response = await container . ReadItemAsync < CustomerV4 > (
485- id : customerId
486- //, partitionKey: new PartitionKey(customerId)
478+ id : customerId ,
479+ partitionKey : new PartitionKey ( customerId )
487480 ) ;
488481 CustomerV4 customer = response . Resource ;
489482
@@ -536,8 +529,8 @@ public static async Task DeleteOrder()
536529 string orderId = "5350ce31-ea50-4df9-9a48-faff97675ac5" ;
537530
538531 ItemResponse < CustomerV4 > response = await container . ReadItemAsync < CustomerV4 > (
539- id : customerId
540- //, partitionKey: new PartitionKey(customerId)
532+ id : customerId ,
533+ partitionKey : new PartitionKey ( customerId )
541534 ) ;
542535 CustomerV4 customer = response . Resource ;
543536
@@ -546,8 +539,7 @@ public static async Task DeleteOrder()
546539
547540 //Submit both as a transactional batch
548541 TransactionalBatchResponse txBatchResponse = await container . CreateTransactionalBatch (
549- //new PartitionKey(customerId)
550- )
542+ new PartitionKey ( customerId ) )
551543 . DeleteItem ( orderId )
552544 . ReplaceItem < CustomerV4 > ( customer . id , customer )
553545 . ExecuteAsync ( ) ;
@@ -633,12 +625,11 @@ private static async Task UpdateProductCategoryName(Container productContainer,
633625 string sql = $ "SELECT * FROM c WHERE c.categoryId = '{ categoryId } '";
634626
635627 FeedIterator < Product > resultSet = productContainer . GetItemQueryIterator < Product > (
636- new QueryDefinition ( sql )
637- //,requestOptions: new QueryRequestOptions
638- //{
639- // PartitionKey = new PartitionKey(categoryId)
640- //}
641- ) ;
628+ new QueryDefinition ( sql ) ,
629+ requestOptions : new QueryRequestOptions
630+ {
631+ PartitionKey = new PartitionKey ( categoryId )
632+ } ) ;
642633
643634 int productCount = 0 ;
644635
0 commit comments