Skip to content

Commit afa3696

Browse files
authored
Update Program.cs
Fixing Partition Key issues
1 parent b3627a3 commit afa3696

File tree

1 file changed

+53
-44
lines changed

1 file changed

+53
-44
lines changed

17-denormalize/Program.cs

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,12 @@ 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-
});
197+
.WithParameter("@id", customerId)
198+
//,requestOptions: new QueryRequestOptions()
199+
//{
200+
// PartitionKey = new PartitionKey(customerId)
201+
//}
202+
);
202203

203204
Console.WriteLine("Query for a single customer\n");
204205
while (resultSet.HasMoreResults)
@@ -227,8 +228,9 @@ public static async Task GetCustomer()
227228

228229
//Get a customer with a point read
229230
ItemResponse<CustomerV2> response = await container.ReadItemAsync<CustomerV2>(
230-
id: customerId,
231-
partitionKey: new PartitionKey(customerId));
231+
id: customerId
232+
//,partitionKey: new PartitionKey(customerId)
233+
);
232234

233235
Print(response.Resource);
234236

@@ -246,11 +248,12 @@ public static async Task ListAllProductCategories()
246248
string sql = $"SELECT * FROM c WHERE c.type = 'category'";
247249

248250
FeedIterator<ProductCategory> resultSet = container.GetItemQueryIterator<ProductCategory>(
249-
new QueryDefinition(sql),
250-
requestOptions: new QueryRequestOptions()
251-
{
252-
PartitionKey = new PartitionKey("category")
253-
});
251+
new QueryDefinition(sql)
252+
//,requestOptions: new QueryRequestOptions()
253+
//{
254+
// PartitionKey = new PartitionKey("category")
255+
//}
256+
);
254257

255258
while (resultSet.HasMoreResults)
256259
{
@@ -280,11 +283,12 @@ public static async Task QueryProductsByCategoryId()
280283

281284
FeedIterator<Product> resultSet = container.GetItemQueryIterator<Product>(
282285
new QueryDefinition(sql)
283-
.WithParameter("@categoryId", categoryId),
284-
requestOptions: new QueryRequestOptions()
285-
{
286-
PartitionKey = new PartitionKey(categoryId)
287-
});
286+
.WithParameter("@categoryId", categoryId)
287+
//,requestOptions: new QueryRequestOptions()
288+
//{
289+
// PartitionKey = new PartitionKey(categoryId)
290+
//}
291+
);
288292

289293
while (resultSet.HasMoreResults)
290294
{
@@ -315,11 +319,12 @@ public static async Task QueryProductsForCategory()
315319
"GROUP BY c.categoryName";
316320

317321
FeedIterator<dynamic> resultSet = container.GetItemQueryIterator<dynamic>(
318-
new QueryDefinition(sql),
319-
requestOptions: new QueryRequestOptions
320-
{
321-
PartitionKey = new PartitionKey(categoryId)
322-
});
322+
new QueryDefinition(sql)
323+
//,requestOptions: new QueryRequestOptions
324+
//{
325+
// PartitionKey = new PartitionKey(categoryId)
326+
//}
327+
);
323328

324329
Console.WriteLine("Print out category name and number of products in that category\n");
325330
while (resultSet.HasMoreResults)
@@ -351,7 +356,7 @@ public static async Task UpdateProductCategory()
351356
};
352357

353358
await container.ReplaceItemAsync(
354-
partitionKey: new PartitionKey("category"),
359+
//partitionKey: new PartitionKey("category"),
355360
id: categoryId,
356361
item: updatedProductCategory);
357362

@@ -374,7 +379,7 @@ public static async Task RevertProductCategory()
374379
Console.WriteLine("Change category name back to original");
375380

376381
await container.ReplaceItemAsync(
377-
partitionKey: new PartitionKey("category"),
382+
//partitionKey: new PartitionKey("category"),
378383
id: categoryId,
379384
item: updatedProductCategory);
380385

@@ -393,11 +398,12 @@ public static async Task QuerySalesOrdersByCustomerId()
393398

394399
FeedIterator<SalesOrder> resultSet = container.GetItemQueryIterator<SalesOrder>(
395400
new QueryDefinition(sql)
396-
.WithParameter("@customerId", customerId),
397-
requestOptions: new QueryRequestOptions
398-
{
399-
PartitionKey = new PartitionKey(customerId)
400-
});
401+
.WithParameter("@customerId", customerId)
402+
//,requestOptions: new QueryRequestOptions
403+
//{
404+
// PartitionKey = new PartitionKey(customerId)
405+
//}
406+
);
401407

402408
Console.WriteLine("Print out orders for this customer\n");
403409
while (resultSet.HasMoreResults)
@@ -424,11 +430,12 @@ public static async Task QueryCustomerAndSalesOrdersByCustomerId()
424430

425431
FeedIterator<dynamic> resultSet = container.GetItemQueryIterator<dynamic>(
426432
new QueryDefinition(sql)
427-
.WithParameter("@customerId", customerId),
428-
requestOptions: new QueryRequestOptions
429-
{
430-
PartitionKey = new PartitionKey(customerId)
431-
});
433+
.WithParameter("@customerId", customerId)
434+
//,requestOptions: new QueryRequestOptions
435+
//{
436+
// PartitionKey = new PartitionKey(customerId)
437+
//}
438+
);
432439

433440
CustomerV4 customer = new CustomerV4();
434441
List<SalesOrder> orders = new List<SalesOrder>();
@@ -475,8 +482,8 @@ public static async Task CreateNewOrderAndUpdateCustomerOrderTotal()
475482
string customerId = "FFD0DD37-1F0E-4E2E-8FAC-EAF45B0E9447";
476483
//Get the customer
477484
ItemResponse<CustomerV4> response = await container.ReadItemAsync<CustomerV4>(
478-
id: customerId,
479-
partitionKey: new PartitionKey(customerId)
485+
id: customerId
486+
//,partitionKey: new PartitionKey(customerId)
480487
);
481488
CustomerV4 customer = response.Resource;
482489

@@ -529,8 +536,8 @@ public static async Task DeleteOrder()
529536
string orderId = "5350ce31-ea50-4df9-9a48-faff97675ac5";
530537

531538
ItemResponse<CustomerV4> response = await container.ReadItemAsync<CustomerV4>(
532-
id: customerId,
533-
partitionKey: new PartitionKey(customerId)
539+
id: customerId
540+
//,partitionKey: new PartitionKey(customerId)
534541
);
535542
CustomerV4 customer = response.Resource;
536543

@@ -539,7 +546,8 @@ public static async Task DeleteOrder()
539546

540547
//Submit both as a transactional batch
541548
TransactionalBatchResponse txBatchResponse = await container.CreateTransactionalBatch(
542-
new PartitionKey(customerId))
549+
//new PartitionKey(customerId)
550+
)
543551
.DeleteItem(orderId)
544552
.ReplaceItem<CustomerV4>(customer.id, customer)
545553
.ExecuteAsync();
@@ -625,11 +633,12 @@ private static async Task UpdateProductCategoryName(Container productContainer,
625633
string sql = $"SELECT * FROM c WHERE c.categoryId = '{categoryId}'";
626634

627635
FeedIterator<Product> resultSet = productContainer.GetItemQueryIterator<Product>(
628-
new QueryDefinition(sql),
629-
requestOptions: new QueryRequestOptions
630-
{
631-
PartitionKey = new PartitionKey(categoryId)
632-
});
636+
new QueryDefinition(sql)
637+
//,requestOptions: new QueryRequestOptions
638+
//{
639+
// PartitionKey = new PartitionKey(categoryId)
640+
//}
641+
);
633642

634643
int productCount = 0;
635644

0 commit comments

Comments
 (0)