Home > Back-end >  How to list tables (by prefix) with Azure.Data.Tables?
How to list tables (by prefix) with Azure.Data.Tables?

Time:03-08

I use Azure.Data.Tables. I found that most likely I should use Azure.Data.Tables.TableServiceClient.QueryAsync(...) (docs) to list tables, however I cannot find any documentation on the syntax of the filter string. I could avoid specifying a filter string and do the filtering on client side but it's not a proper way to do it.

There is only one example in the docs:

filter
String
Returns only tables that satisfy the specified filter. For example, the following would filter tables with a Name of 'foo': "TableName eq 'foo'".

But where is the full documentation for the filter string, and more specifically, how can I list tables by prefix? In Microsoft.Azure.Cosmos.Table.CloudTableClient.ListTables it seems it can be done easily (docs) but microsoft recommends moving to Azure.Data.Tables.

CodePudding user response:

As of version 12.4.0 of Azure.Data.Tables SDK, it is not possible.

However I did find an issue on SDK repository on GitHub: https://github.com/Azure/azure-sdk-for-net/issues/24414 which pointed me to a workaround here: https://github.com/NuGet/Insights/blob/6d23681b17d7c131f7f2ab25b111fc4bcb421ba6/src/ExplorePackages.Logic/Storage/TableExtensions.cs.

From the 2nd link:

public static AsyncPageable<TableItem> GetTablesAsync(this TableServiceClient client, string prefix)
{
    var prefixQuery = TableClient.CreateQueryFilter<TableItem>(
        x => x.TableName.CompareTo(prefix) >= 0
          && x.TableName.CompareTo(prefix   char.MaxValue) <= 0);

    return client.GetTablesAsync(filter: prefixQuery);
}
  • Related