public async Task GetTablesReturnsTables() { string tableName = $"testtable{Recording.GenerateId()}"; bool doCleanup = false; TableServiceClient service = CreateTableServiceClient(); try { var createdTable = await service.CreateTableAsync(tableName).ConfigureAwait(false); Assert.That(() => createdTable.TableName, Is.EqualTo(tableName), $"Created table should be {tableName}"); doCleanup = true; List <TableResponseProperties> tableResponses = new List <TableResponseProperties>(); await foreach (var table in service.GetTablesAsync()) { tableResponses.Add(table); } Assert.That(() => tableResponses, Is.Not.Empty); Assert.That(() => tableResponses.Select(r => r.TableName), Contains.Item(tableName)); } finally { if (doCleanup) { await service.DeleteTableAsync(tableName); } } }
public async Task QueryTablesAsync() { string storageUri = StorageUri; string accountName = StorageAccountName; string storageAccountKey = PrimaryStorageAccountKey; string tableName = "OfficeSupplies3p2"; var serviceClient = new TableServiceClient( new Uri(storageUri), new TableSharedKeyCredential(accountName, storageAccountKey)); await serviceClient.CreateTableAsync(tableName); #region Snippet:TablesSample3QueryTablesAsync // Use the <see cref="TableServiceClient"> to query the service. Passing in OData filter strings is optional. AsyncPageable <TableItem> queryTableResults = serviceClient.GetTablesAsync(filter: $"TableName eq '{tableName}'"); Console.WriteLine("The following are the names of the tables in the query result:"); // Iterate the <see cref="Pageable"> in order to access individual queried tables. await foreach (TableItem table in queryTableResults) { Console.WriteLine(table.TableName); } #endregion await serviceClient.DeleteTableAsync(tableName); }
public async Task GetTablesReturnsTablesWithFilter() { string tableName = $"testtable{Recording.GenerateId()}"; bool doCleanup = false; TableServiceClient service = CreateTableServiceClient(); try { var createdTable = await service.CreateTableAsync(tableName).ConfigureAwait(false); Assert.That(() => createdTable.TableName, Is.EqualTo(tableName), $"Created table should be '{tableName}'"); doCleanup = true; // Query with a filter. var tableResponses = (await service.GetTablesAsync(filter: $"TableName eq '{tableName}'").ToEnumerableAsync().ConfigureAwait(false)).ToList(); Assert.That(() => tableResponses, Is.Not.Empty); Assert.That(() => tableResponses.Select(r => r.TableName), Contains.Item(tableName)); } finally { if (doCleanup) { await service.DeleteTableAsync(tableName); } } }
public static async Task Main(string[] args) { var serviceClient = new TableServiceClient( new Uri("https://pakrym0test0storage.table.core.windows.net"), new StorageSharedKeyCredential("pakrym0test0storage", args[0])); await foreach (var table in serviceClient.GetTablesAsync()) { Console.WriteLine(table.TableName); } var tableClient = serviceClient.GetTableClient("mytesttable2"); var currentTime = DateTimeOffset.Now; var timestamp = currentTime.Ticks.ToString(); Console.WriteLine("Type in a message:"); var message = Console.ReadLine(); Console.WriteLine("Type in a number:"); var number = int.Parse(Console.ReadLine()); await tableClient.InsertAsync(new Dictionary <string, object>() { { "Number", number }, { "Time", currentTime }, { "Message", message }, { "PartitionKey", timestamp }, { "RowKey", timestamp } }); Console.WriteLine("What number do you want?"); var filter = int.Parse(Console.ReadLine()); await foreach (var entity in tableClient.QueryAsync(select: "Time,Message", filter: $"Number eq {filter}")) { Console.WriteLine($"{entity["Time"]} {entity["Message"]}"); } }