Skip to content

Commit

Permalink
fix tables samples so they build (#33998)
Browse files Browse the repository at this point in the history
  • Loading branch information
christothes committed Feb 8, 2023
1 parent 5cfd4af commit 6fb0cd6
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 77 deletions.
2 changes: 1 addition & 1 deletion sdk/tables/Azure.Data.Tables/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release History

## 12.8.0 (2023-02-07)
## 12.8.0 (2023-02-08)

### Bugs Fixed
- Fixed an issue where LINQ predicates containing New expressions, such as `ent => ent.TimeStamp > new DateTimeOffset(...)`, threw an exception.
Expand Down
3 changes: 1 addition & 2 deletions sdk/tables/Azure.Data.Tables/MigrationGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ any one table, it is ideal for scenarios where you need to create, delete, or li

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

```C# Snippet:TablesMigrationUpsertEntity
// Upsert the newly created entity.
tableClient.UpsertEntity(entity);
tableClient.UpsertEntity(tableEntity);
```

### Fetching a single entity from the table
Expand Down
8 changes: 3 additions & 5 deletions sdk/tables/Azure.Data.Tables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ Next, we can create a new table.

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

```C# Snippet:TablesSample1DeleteTable
// Deletes the table made previously.
string tableName = "OfficeSupplies1p1";
serviceClient.DeleteTable(tableName);
```

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

```C# Snippet:TablesSample2CreateDictionaryEntity
// Make a dictionary entity by defining a <see cref="TableEntity">.
var entity = new TableEntity(partitionKey, rowKey)
var tableEntity = new TableEntity(partitionKey, rowKey)
{
{ "Product", "Marker Set" },
{ "Price", 5.00 },
{ "Quantity", 21 }
};

Console.WriteLine($"{entity.RowKey}: {entity["Product"]} costs ${entity.GetDouble("Price")}.");
Console.WriteLine($"{tableEntity.RowKey}: {tableEntity["Product"]} costs ${tableEntity.GetDouble("Price")}.");
```

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

```C# Snippet:TablesSample2AddEntity
// Add the newly created entity.
tableClient.AddEntity(entity);
tableClient.AddEntity(tableEntity);
```

### Query table entities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ A `TableClient` is needed to perform table-level operations like inserting and d
- Call `GetTableClient` from the `TableServiceClient` with the table name.

```C# Snippet:TablesSample1GetTableClient
string tableName = "OfficeSupplies1p2";
var tableClient = serviceClient.GetTableClient(tableName);
var tableClient2 = serviceClient.GetTableClient(tableName);
```

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

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

### Using `TableServiceClient`

To create a table, invoke `CreateTable` with the table name.
To create a table, invoke `CreateTableIfNotExists` with the table name.

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

### Using `TableClient`

To create a table, invoke `Create` with the table name.
To create a table, invoke `CreateIfNotExists` with the table name.

```C# Snippet:TablesSample1TableClientCreateTable
tableClient.CreateIfNotExists();
tableClient3.CreateIfNotExists();
```

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

```C# Snippet:TablesSample1DeleteTable
// Deletes the table made previously.
string tableName = "OfficeSupplies1p1";
serviceClient.DeleteTable(tableName);
```

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

```C# Snippet:TablesSample1TableClientDeleteTable
tableClient.Delete();
tableClient3.Delete();
```

## Handle errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ A `TableClient` is needed to perform table-level operations like inserting and d
- Call `GetTableClient` from the `TableServiceClient` with the table name.

```C# Snippet:TablesSample1GetTableClient
string tableName = "OfficeSupplies1p2";
var tableClient = serviceClient.GetTableClient(tableName);
var tableClient2 = serviceClient.GetTableClient(tableName);
```

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

```C# Snippet:TablesSample1CreateTableClient
var tableClient = new TableClient(
var tableClient3 = new TableClient(
new Uri(storageUri),
tableName,
new TableSharedKeyCredential(accountName, storageAccountKey));
Expand Down Expand Up @@ -58,7 +57,7 @@ var strongEntity = new OfficeSupplyEntity
Quantity = 50
};

Console.WriteLine($"{entity.RowKey}: {strongEntity.Product} costs ${strongEntity.Price}.");
Console.WriteLine($"{tableEntity.RowKey}: {strongEntity.Product} costs ${strongEntity.Price}.");
```

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

```C# Snippet:TablesSample2CreateDictionaryEntity
// Make a dictionary entity by defining a <see cref="TableEntity">.
var entity = new TableEntity(partitionKey, rowKey)
var tableEntity = new TableEntity(partitionKey, rowKey)
{
{ "Product", "Marker Set" },
{ "Price", 5.00 },
{ "Quantity", 21 }
};

Console.WriteLine($"{entity.RowKey}: {entity["Product"]} costs ${entity.GetDouble("Price")}.");
Console.WriteLine($"{tableEntity.RowKey}: {tableEntity["Product"]} costs ${tableEntity.GetDouble("Price")}.");
```

## Add an entity

To add the entity to the table, invoke `CreateEntity` and pass in the newly created entity.
To add the entity to the table, invoke `AddEntity` and pass in the newly created entity.

```C# Snippet:TablesSample2AddEntity
// Add the newly created entity.
tableClient.AddEntity(entity);
tableClient.AddEntity(tableEntity);
```

## Delete an entity
Expand Down
9 changes: 4 additions & 5 deletions sdk/tables/Azure.Data.Tables/samples/Sample4QueryEntities.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ A `TableClient` is needed to perform table-level operations like inserting and d
- Call `GetTableClient` from the `TableServiceClient` with the table name.

```C# Snippet:TablesSample1GetTableClient
string tableName = "OfficeSupplies1p2";
var tableClient = serviceClient.GetTableClient(tableName);
var tableClient2 = serviceClient.GetTableClient(tableName);
```

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

```C# Snippet:TablesSample1CreateTableClient
var tableClient = new TableClient(
var tableClient3 = new TableClient(
new Uri(storageUri),
tableName,
new TableSharedKeyCredential(accountName, storageAccountKey));
Expand Down Expand Up @@ -49,9 +48,9 @@ The `QueryFilter` class handles all the type escaping for you.

```C# Snippet:TablesSample4QueryEntitiesFilterWithQueryFilter
// The CreateQueryFilter method is also available to assist with properly formatting and escaping OData queries.
Pageable<TableEntity> queryResultsFilter = tableClient.Query<TableEntity>(filter: TableClient.CreateQueryFilter($"PartitionKey eq {partitionKey}"));
var queryResultsFilter2 = tableClient.Query<TableEntity>(filter: TableClient.CreateQueryFilter($"PartitionKey eq {partitionKey}"));
// Iterate the <see cref="Pageable"> to access all queried entities.
foreach (TableEntity qEntity in queryResultsFilter)
foreach (TableEntity qEntity in queryResultsFilter2)
{
Console.WriteLine($"{qEntity.GetString("Product")}: {qEntity.GetDouble("Price")}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ A `TableClient` is needed to perform table-level operations like inserting and d
- Call `GetTableClient` from the `TableServiceClient` with the table name.

```C# Snippet:TablesSample1GetTableClient
string tableName = "OfficeSupplies1p2";
var tableClient = serviceClient.GetTableClient(tableName);
var tableClient2 = serviceClient.GetTableClient(tableName);
```

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

```C# Snippet:TablesSample1CreateTableClient
var tableClient = new TableClient(
var tableClient3 = new TableClient(
new Uri(storageUri),
tableName,
new TableSharedKeyCredential(accountName, storageAccountKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ A `TableClient` is needed to perform table-level operations like inserting and d
- Call `GetTableClient` from the `TableServiceClient` with the table name.

```C# Snippet:TablesSample1GetTableClient
string tableName = "OfficeSupplies1p2";
var tableClient = serviceClient.GetTableClient(tableName);
var tableClient2 = serviceClient.GetTableClient(tableName);
```

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

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

```C# Snippet:BatchAdd
// Create a list of 5 entities with the same partition key.
string partitionKey = "BatchInsertSample";
string batchPartitionKey = "BatchInsertSample";
List<TableEntity> entityList = new List<TableEntity>
{
new TableEntity(partitionKey, "01")
new TableEntity(batchPartitionKey, "01")
{
{ "Product", "Marker" },
{ "Price", 5.00 },
{ "Brand", "Premium" }
},
new TableEntity(partitionKey, "02")
new TableEntity(batchPartitionKey, "02")
{
{ "Product", "Pen" },
{ "Price", 3.00 },
{ "Brand", "Premium" }
},
new TableEntity(partitionKey, "03")
new TableEntity(batchPartitionKey, "03")
{
{ "Product", "Paper" },
{ "Price", 0.10 },
{ "Brand", "Premium" }
},
new TableEntity(partitionKey, "04")
new TableEntity(batchPartitionKey, "04")
{
{ "Product", "Glue" },
{ "Price", 1.00 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public void CreateDeleteTable()

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

#region Snippet:TablesSample1DeleteTable
// Deletes the table made previously.
#if SNIPPET
string tableName = "OfficeSupplies1p1";
#endif
serviceClient.DeleteTable(tableName);
#endregion

#region Snippet:TablesSample1GetTableClient
#if SNIPPET
string tableName = "OfficeSupplies1p2";
var tableClient = serviceClient.GetTableClient(tableName);
#else
#if !SNIPPET
tableName = "OfficeSupplies1p2" + _random.Next();
tableClient = serviceClient.GetTableClient(tableName);
#endif
var tableClient2 = serviceClient.GetTableClient(tableName);
#endregion

#region Snippet:TablesSample1CreateTableClient
#if SNIPPET
var tableClient = new TableClient(
#else
tableClient = new TableClient(
#endif
var tableClient3 = new TableClient(
new Uri(storageUri),
tableName,
new TableSharedKeyCredential(accountName, storageAccountKey));
#endregion

#region Snippet:TablesSample1TableClientCreateTable
tableClient.CreateIfNotExists();
tableClient3.CreateIfNotExists();
#endregion

#region Snippet:TablesSample1TableClientDeleteTable
tableClient.Delete();
tableClient3.Delete();
#endregion
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ public void CreateDeleteEntity()

#region Snippet:TablesSample2CreateDictionaryEntity
// Make a dictionary entity by defining a <see cref="TableEntity">.
var entity = new TableEntity(partitionKey, rowKey)
var tableEntity = new TableEntity(partitionKey, rowKey)
{
{ "Product", "Marker Set" },
{ "Price", 5.00 },
{ "Quantity", 21 }
};

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

#region Snippet:TablesSample2AddEntity
// Add the newly created entity.
tableClient.AddEntity(entity);
tableClient.AddEntity(tableEntity);
#endregion

#region Snippet:TablesMigrationUpsertEntity
// Upsert the newly created entity.
tableClient.UpsertEntity(entity);
tableClient.UpsertEntity(tableEntity);
#endregion

#region Snippet:TablesSample2CreateStronglyTypedEntity
Expand All @@ -65,7 +65,7 @@ public void CreateDeleteEntity()
Quantity = 50
};

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

#region Snippet:TablesMigrationCreateEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,9 @@ public void QueryEntities()

#region Snippet:TablesSample4QueryEntitiesFilterWithQueryFilter
// The CreateQueryFilter method is also available to assist with properly formatting and escaping OData queries.
#if SNIPPET
Pageable<TableEntity> queryResultsFilter = tableClient.Query<TableEntity>(filter: TableClient.CreateQueryFilter($"PartitionKey eq {partitionKey}"));
#else
queryResultsFilter = tableClient.Query<TableEntity>(filter: TableClient.CreateQueryFilter($"PartitionKey eq {partitionKey}"));
#endif
var queryResultsFilter2 = tableClient.Query<TableEntity>(filter: TableClient.CreateQueryFilter($"PartitionKey eq {partitionKey}"));
// Iterate the <see cref="Pageable"> to access all queried entities.
foreach (TableEntity qEntity in queryResultsFilter)
foreach (TableEntity qEntity in queryResultsFilter2)
{
Console.WriteLine($"{qEntity.GetString("Product")}: {qEntity.GetDouble("Price")}");
}
Expand Down

0 comments on commit 6fb0cd6

Please sign in to comment.