Skip to content

Commit 6fb0cd6

Browse files
authored
fix tables samples so they build (Azure#33998)
1 parent 5cfd4af commit 6fb0cd6

12 files changed

+48
-77
lines changed

sdk/tables/Azure.Data.Tables/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release History
22

3-
## 12.8.0 (2023-02-07)
3+
## 12.8.0 (2023-02-08)
44

55
### Bugs Fixed
66
- Fixed an issue where LINQ predicates containing New expressions, such as `ent => ent.TimeStamp > new DateTimeOffset(...)`, threw an exception.

sdk/tables/Azure.Data.Tables/MigrationGuide.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ any one table, it is ideal for scenarios where you need to create, delete, or li
7878

7979
```C# Snippet:TablesSample1CreateTable
8080
// Create a new table. The TableItem class stores properties of the created table.
81-
string tableName = "OfficeSupplies1p1";
8281
TableItem table = serviceClient.CreateTableIfNotExists(tableName);
8382
Console.WriteLine($"The created table's name is {table.Name}.");
8483
```
@@ -175,7 +174,7 @@ or not it already exists.
175174

176175
```C# Snippet:TablesMigrationUpsertEntity
177176
// Upsert the newly created entity.
178-
tableClient.UpsertEntity(entity);
177+
tableClient.UpsertEntity(tableEntity);
179178
```
180179

181180
### Fetching a single entity from the table

sdk/tables/Azure.Data.Tables/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ Next, we can create a new table.
108108

109109
```C# Snippet:TablesSample1CreateTable
110110
// Create a new table. The TableItem class stores properties of the created table.
111-
string tableName = "OfficeSupplies1p1";
112111
TableItem table = serviceClient.CreateTableIfNotExists(tableName);
113112
Console.WriteLine($"The created table's name is {table.Name}.");
114113
```
@@ -137,7 +136,6 @@ Individual tables can be deleted from the service.
137136

138137
```C# Snippet:TablesSample1DeleteTable
139138
// Deletes the table made previously.
140-
string tableName = "OfficeSupplies1p1";
141139
serviceClient.DeleteTable(tableName);
142140
```
143141

@@ -162,21 +160,21 @@ Let's define a new `TableEntity` so that we can add it to the table.
162160

163161
```C# Snippet:TablesSample2CreateDictionaryEntity
164162
// Make a dictionary entity by defining a <see cref="TableEntity">.
165-
var entity = new TableEntity(partitionKey, rowKey)
163+
var tableEntity = new TableEntity(partitionKey, rowKey)
166164
{
167165
{ "Product", "Marker Set" },
168166
{ "Price", 5.00 },
169167
{ "Quantity", 21 }
170168
};
171169

172-
Console.WriteLine($"{entity.RowKey}: {entity["Product"]} costs ${entity.GetDouble("Price")}.");
170+
Console.WriteLine($"{tableEntity.RowKey}: {tableEntity["Product"]} costs ${tableEntity.GetDouble("Price")}.");
173171
```
174172

175173
Using the `TableClient` we can now add our new entity to the table.
176174

177175
```C# Snippet:TablesSample2AddEntity
178176
// Add the newly created entity.
179-
tableClient.AddEntity(entity);
177+
tableClient.AddEntity(tableEntity);
180178
```
181179

182180
### Query table entities

sdk/tables/Azure.Data.Tables/samples/Sample1CreateDeleteTables.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ A `TableClient` is needed to perform table-level operations like inserting and d
2222
- Call `GetTableClient` from the `TableServiceClient` with the table name.
2323

2424
```C# Snippet:TablesSample1GetTableClient
25-
string tableName = "OfficeSupplies1p2";
26-
var tableClient = serviceClient.GetTableClient(tableName);
25+
var tableClient2 = serviceClient.GetTableClient(tableName);
2726
```
2827

2928
- Create a `TableClient` with a SAS URI, an endpoint and `TableSharedKeyCredential`, or a connection string.
3029

3130
```C# Snippet:TablesSample1CreateTableClient
32-
var tableClient = new TableClient(
31+
var tableClient3 = new TableClient(
3332
new Uri(storageUri),
3433
tableName,
3534
new TableSharedKeyCredential(accountName, storageAccountKey));
@@ -41,21 +40,20 @@ A table requires a [unique table name](https://docs.microsoft.com/rest/api/stora
4140

4241
### Using `TableServiceClient`
4342

44-
To create a table, invoke `CreateTable` with the table name.
43+
To create a table, invoke `CreateTableIfNotExists` with the table name.
4544

4645
```C# Snippet:TablesSample1CreateTable
4746
// Create a new table. The TableItem class stores properties of the created table.
48-
string tableName = "OfficeSupplies1p1";
4947
TableItem table = serviceClient.CreateTableIfNotExists(tableName);
5048
Console.WriteLine($"The created table's name is {table.Name}.");
5149
```
5250

5351
### Using `TableClient`
5452

55-
To create a table, invoke `Create` with the table name.
53+
To create a table, invoke `CreateIfNotExists` with the table name.
5654

5755
```C# Snippet:TablesSample1TableClientCreateTable
58-
tableClient.CreateIfNotExists();
56+
tableClient3.CreateIfNotExists();
5957
```
6058

6159
## Delete a table
@@ -66,7 +64,6 @@ To delete the table, invoke `DeleteTable` with the table name.
6664

6765
```C# Snippet:TablesSample1DeleteTable
6866
// Deletes the table made previously.
69-
string tableName = "OfficeSupplies1p1";
7067
serviceClient.DeleteTable(tableName);
7168
```
7269

@@ -75,7 +72,7 @@ serviceClient.DeleteTable(tableName);
7572
To delete the table, invoke `Delete` with the table name.
7673

7774
```C# Snippet:TablesSample1TableClientDeleteTable
78-
tableClient.Delete();
75+
tableClient3.Delete();
7976
```
8077

8178
## Handle errors

sdk/tables/Azure.Data.Tables/samples/Sample2CreateDeleteEntities.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ A `TableClient` is needed to perform table-level operations like inserting and d
88
- Call `GetTableClient` from the `TableServiceClient` with the table name.
99

1010
```C# Snippet:TablesSample1GetTableClient
11-
string tableName = "OfficeSupplies1p2";
12-
var tableClient = serviceClient.GetTableClient(tableName);
11+
var tableClient2 = serviceClient.GetTableClient(tableName);
1312
```
1413

1514
- Create a `TableClient` with a SAS URI, an endpoint and `TableSharedKeyCredential`, or a connection string.
1615

1716
```C# Snippet:TablesSample1CreateTableClient
18-
var tableClient = new TableClient(
17+
var tableClient3 = new TableClient(
1918
new Uri(storageUri),
2019
tableName,
2120
new TableSharedKeyCredential(accountName, storageAccountKey));
@@ -58,7 +57,7 @@ var strongEntity = new OfficeSupplyEntity
5857
Quantity = 50
5958
};
6059

61-
Console.WriteLine($"{entity.RowKey}: {strongEntity.Product} costs ${strongEntity.Price}.");
60+
Console.WriteLine($"{tableEntity.RowKey}: {strongEntity.Product} costs ${strongEntity.Price}.");
6261
```
6362

6463
### Dictionary entity
@@ -69,23 +68,23 @@ Properties accessed using the indexer `[]` will be typed as an `object`, but `Ta
6968

7069
```C# Snippet:TablesSample2CreateDictionaryEntity
7170
// Make a dictionary entity by defining a <see cref="TableEntity">.
72-
var entity = new TableEntity(partitionKey, rowKey)
71+
var tableEntity = new TableEntity(partitionKey, rowKey)
7372
{
7473
{ "Product", "Marker Set" },
7574
{ "Price", 5.00 },
7675
{ "Quantity", 21 }
7776
};
7877

79-
Console.WriteLine($"{entity.RowKey}: {entity["Product"]} costs ${entity.GetDouble("Price")}.");
78+
Console.WriteLine($"{tableEntity.RowKey}: {tableEntity["Product"]} costs ${tableEntity.GetDouble("Price")}.");
8079
```
8180

8281
## Add an entity
8382

84-
To add the entity to the table, invoke `CreateEntity` and pass in the newly created entity.
83+
To add the entity to the table, invoke `AddEntity` and pass in the newly created entity.
8584

8685
```C# Snippet:TablesSample2AddEntity
8786
// Add the newly created entity.
88-
tableClient.AddEntity(entity);
87+
tableClient.AddEntity(tableEntity);
8988
```
9089

9190
## Delete an entity

sdk/tables/Azure.Data.Tables/samples/Sample4QueryEntities.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ A `TableClient` is needed to perform table-level operations like inserting and d
88
- Call `GetTableClient` from the `TableServiceClient` with the table name.
99

1010
```C# Snippet:TablesSample1GetTableClient
11-
string tableName = "OfficeSupplies1p2";
12-
var tableClient = serviceClient.GetTableClient(tableName);
11+
var tableClient2 = serviceClient.GetTableClient(tableName);
1312
```
1413

1514
- Create a `TableClient` with a SAS URI, an endpoint and `TableSharedKeyCredential`, or a connection string.
1615

1716
```C# Snippet:TablesSample1CreateTableClient
18-
var tableClient = new TableClient(
17+
var tableClient3 = new TableClient(
1918
new Uri(storageUri),
2019
tableName,
2120
new TableSharedKeyCredential(accountName, storageAccountKey));
@@ -49,9 +48,9 @@ The `QueryFilter` class handles all the type escaping for you.
4948

5049
```C# Snippet:TablesSample4QueryEntitiesFilterWithQueryFilter
5150
// The CreateQueryFilter method is also available to assist with properly formatting and escaping OData queries.
52-
Pageable<TableEntity> queryResultsFilter = tableClient.Query<TableEntity>(filter: TableClient.CreateQueryFilter($"PartitionKey eq {partitionKey}"));
51+
var queryResultsFilter2 = tableClient.Query<TableEntity>(filter: TableClient.CreateQueryFilter($"PartitionKey eq {partitionKey}"));
5352
// Iterate the <see cref="Pageable"> to access all queried entities.
54-
foreach (TableEntity qEntity in queryResultsFilter)
53+
foreach (TableEntity qEntity in queryResultsFilter2)
5554
{
5655
Console.WriteLine($"{qEntity.GetString("Product")}: {qEntity.GetDouble("Price")}");
5756
}

sdk/tables/Azure.Data.Tables/samples/Sample5UpdateUpsertEntities.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ A `TableClient` is needed to perform table-level operations like inserting and d
88
- Call `GetTableClient` from the `TableServiceClient` with the table name.
99

1010
```C# Snippet:TablesSample1GetTableClient
11-
string tableName = "OfficeSupplies1p2";
12-
var tableClient = serviceClient.GetTableClient(tableName);
11+
var tableClient2 = serviceClient.GetTableClient(tableName);
1312
```
1413

1514
- Create a `TableClient` with a SAS URI, an endpoint and `TableSharedKeyCredential`, or a connection string.
1615

1716
```C# Snippet:TablesSample1CreateTableClient
18-
var tableClient = new TableClient(
17+
var tableClient3 = new TableClient(
1918
new Uri(storageUri),
2019
tableName,
2120
new TableSharedKeyCredential(accountName, storageAccountKey));

sdk/tables/Azure.Data.Tables/samples/Sample6TransactionalBatch.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ A `TableClient` is needed to perform table-level operations like inserting and d
1313
- Call `GetTableClient` from the `TableServiceClient` with the table name.
1414

1515
```C# Snippet:TablesSample1GetTableClient
16-
string tableName = "OfficeSupplies1p2";
17-
var tableClient = serviceClient.GetTableClient(tableName);
16+
var tableClient2 = serviceClient.GetTableClient(tableName);
1817
```
1918

2019
- Create a `TableClient` with a SAS URI, an endpoint and `TableSharedKeyCredential`, or a connection string.
2120

2221
```C# Snippet:TablesSample1CreateTableClient
23-
var tableClient = new TableClient(
22+
var tableClient3 = new TableClient(
2423
new Uri(storageUri),
2524
tableName,
2625
new TableSharedKeyCredential(accountName, storageAccountKey));
@@ -34,28 +33,28 @@ A common use case for batch operations is to add many entities to a table in bul
3433

3534
```C# Snippet:BatchAdd
3635
// Create a list of 5 entities with the same partition key.
37-
string partitionKey = "BatchInsertSample";
36+
string batchPartitionKey = "BatchInsertSample";
3837
List<TableEntity> entityList = new List<TableEntity>
3938
{
40-
new TableEntity(partitionKey, "01")
39+
new TableEntity(batchPartitionKey, "01")
4140
{
4241
{ "Product", "Marker" },
4342
{ "Price", 5.00 },
4443
{ "Brand", "Premium" }
4544
},
46-
new TableEntity(partitionKey, "02")
45+
new TableEntity(batchPartitionKey, "02")
4746
{
4847
{ "Product", "Pen" },
4948
{ "Price", 3.00 },
5049
{ "Brand", "Premium" }
5150
},
52-
new TableEntity(partitionKey, "03")
51+
new TableEntity(batchPartitionKey, "03")
5352
{
5453
{ "Product", "Paper" },
5554
{ "Price", 0.10 },
5655
{ "Brand", "Premium" }
5756
},
58-
new TableEntity(partitionKey, "04")
57+
new TableEntity(batchPartitionKey, "04")
5958
{
6059
{ "Product", "Glue" },
6160
{ "Price", 1.00 },

sdk/tables/Azure.Data.Tables/tests/samples/Sample1_CreateDeleteTable.cs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ public void CreateDeleteTable()
2929

3030
#region Snippet:TablesSample1CreateTable
3131
// Create a new table. The TableItem class stores properties of the created table.
32-
#if SNIPPET
33-
string tableName = "OfficeSupplies1p1";
34-
#endif
3532
TableItem table = serviceClient.CreateTableIfNotExists(tableName);
3633
Console.WriteLine($"The created table's name is {table.Name}.");
3734
#endregion
@@ -46,39 +43,29 @@ public void CreateDeleteTable()
4643

4744
#region Snippet:TablesSample1DeleteTable
4845
// Deletes the table made previously.
49-
#if SNIPPET
50-
string tableName = "OfficeSupplies1p1";
51-
#endif
5246
serviceClient.DeleteTable(tableName);
5347
#endregion
5448

5549
#region Snippet:TablesSample1GetTableClient
56-
#if SNIPPET
57-
string tableName = "OfficeSupplies1p2";
58-
var tableClient = serviceClient.GetTableClient(tableName);
59-
#else
50+
#if !SNIPPET
6051
tableName = "OfficeSupplies1p2" + _random.Next();
61-
tableClient = serviceClient.GetTableClient(tableName);
6252
#endif
53+
var tableClient2 = serviceClient.GetTableClient(tableName);
6354
#endregion
6455

6556
#region Snippet:TablesSample1CreateTableClient
66-
#if SNIPPET
67-
var tableClient = new TableClient(
68-
#else
69-
tableClient = new TableClient(
70-
#endif
57+
var tableClient3 = new TableClient(
7158
new Uri(storageUri),
7259
tableName,
7360
new TableSharedKeyCredential(accountName, storageAccountKey));
7461
#endregion
7562

7663
#region Snippet:TablesSample1TableClientCreateTable
77-
tableClient.CreateIfNotExists();
64+
tableClient3.CreateIfNotExists();
7865
#endregion
7966

8067
#region Snippet:TablesSample1TableClientDeleteTable
81-
tableClient.Delete();
68+
tableClient3.Delete();
8269
#endregion
8370
}
8471
}

sdk/tables/Azure.Data.Tables/tests/samples/Sample2_CreateDeleteEntities.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ public void CreateDeleteEntity()
3434

3535
#region Snippet:TablesSample2CreateDictionaryEntity
3636
// Make a dictionary entity by defining a <see cref="TableEntity">.
37-
var entity = new TableEntity(partitionKey, rowKey)
37+
var tableEntity = new TableEntity(partitionKey, rowKey)
3838
{
3939
{ "Product", "Marker Set" },
4040
{ "Price", 5.00 },
4141
{ "Quantity", 21 }
4242
};
4343

44-
Console.WriteLine($"{entity.RowKey}: {entity["Product"]} costs ${entity.GetDouble("Price")}.");
44+
Console.WriteLine($"{tableEntity.RowKey}: {tableEntity["Product"]} costs ${tableEntity.GetDouble("Price")}.");
4545
#endregion
4646

4747
#region Snippet:TablesSample2AddEntity
4848
// Add the newly created entity.
49-
tableClient.AddEntity(entity);
49+
tableClient.AddEntity(tableEntity);
5050
#endregion
5151

5252
#region Snippet:TablesMigrationUpsertEntity
5353
// Upsert the newly created entity.
54-
tableClient.UpsertEntity(entity);
54+
tableClient.UpsertEntity(tableEntity);
5555
#endregion
5656

5757
#region Snippet:TablesSample2CreateStronglyTypedEntity
@@ -65,7 +65,7 @@ public void CreateDeleteEntity()
6565
Quantity = 50
6666
};
6767

68-
Console.WriteLine($"{entity.RowKey}: {strongEntity.Product} costs ${strongEntity.Price}.");
68+
Console.WriteLine($"{tableEntity.RowKey}: {strongEntity.Product} costs ${strongEntity.Price}.");
6969
#endregion
7070

7171
#region Snippet:TablesMigrationCreateEntity

0 commit comments

Comments
 (0)