Azure Table: Query Entities with Filter, Projection, and Pagination
See more Azure Table Service Examples
Follows NextPartitionKey and optional NextRowKey continuation headers, including empty pages. Tokens are opaque and encoded by AddQueryParam. Preserves original query options, detects token cycles, and bounds the number of pages. $top limits each response page, not the entire scan. Process result.value before requesting the next page; this example reports counts without printing values. Enumeration is not a point-in-time snapshot.
Targets Azure Storage Table service in the public cloud, not Azure Cosmos DB for Table. Uses Chilkat 11.6.0 or later and an unlocked library. Direct data requests pin x-ms-version 2026-04-06 and OData 3.0. Shared Key examples read private qa_data/azure/storage.json with account and access_key string fields. Authentication examples explain their additional fields. Create private local directories before running; keep credentials, tokens, SAS, entity values, checkpoints and diagnostics outside public content and source control.
HTTPS certificates are verified. Transport completion and HTTP status are checked separately. Writes are not automatically retried after an uncertain outcome. Entity keys, ETags and continuation tokens remain strings. Examples operate on the existing ExampleCustomers table unless noted; review the targets before adapting them. Microsoft Entra ID with suitable Table data roles is preferred where available.
Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// StringBuilder compares text by value in every generated language.
final textCompare = CkStringBuilder();
// Assumes Chilkat is unlocked. See Global Unlock Sample.
final config = CkJsonObject();
config.strict = true;
try {
config.loadFile('qa_data/azure/storage.json');
} on ChilkatException {
print('Could not load private Azure configuration.');
return;
}
textCompare.clear();
textCompare.setString(config.stringOf('account'));
final sameText1 = textCompare.contentsEqual('', true);
if ((config.jsonTypeOf('account') != 1) || (sameText1)) {
print('Supply the storage account name.');
return;
}
// access_key is the base64 account key, not a connection string or SAS.
textCompare.clear();
textCompare.setString(config.stringOf('access_key'));
final sameText2 = textCompare.contentsEqual('', true);
if ((config.jsonTypeOf('access_key') != 1) || (sameText2)) {
print('Supply the base64 account access key.');
return;
}
final accountText = CkStringBuilder();
try {
accountText.append(config.stringOf('account'));
} on ChilkatException {
print('Could not prepare the request.');
return;
}
if ((accountText.length < 3) || (accountText.length > 24)) {
print('Storage account names need 3-24 lowercase letters or digits.');
return;
}
final allowedAccountChars = CkStringBuilder();
try {
allowedAccountChars.append('abcdefghijklmnopqrstuvwxyz0123456789');
} on ChilkatException {
print('Could not prepare the request.');
return;
}
var charIndex = 0;
while (charIndex < accountText.length) {
if (!allowedAccountChars.contains(accountText.getRange(charIndex, 1, false), true)) {
print('Storage account names need lowercase letters or digits.');
return;
}
charIndex++;
}
final endpoint = CkStringBuilder();
try {
endpoint.append(config.stringOf('account'));
} on ChilkatException {
print('Could not prepare the request.');
return;
}
try {
endpoint.append('.table.core.windows.net');
} on ChilkatException {
print('Could not prepare the request.');
return;
}
// Table names contain only letters and digits and are case-insensitive.
// Entity PartitionKey and RowKey values are case-sensitive.
final resourcePath = '/ExampleCustomers()';
final rest = CkRest();
rest.connectTimeoutMs = 20000;
rest.idleTimeoutMs = 60000;
final azAuth = CkAuthAzureStorage();
azAuth.account = config.stringOf('account');
azAuth.accessKey = config.stringOf('access_key');
azAuth.service = 'Table';
azAuth.scheme = 'SharedKey';
azAuth.xMsVersion = '2026-04-06';
try {
rest.setAuthAzureStorage(azAuth);
} on ChilkatException {
print('Could not configure Shared Key signing.');
return;
}
final connection = CkSocket();
connection.requireSslCertVerify = true;
connection.maxReadIdleMs = 60000;
connection.maxSendIdleMs = 60000;
try {
connection.connect(endpoint.getAsString(), 443, true, 20000);
} on ChilkatException {
print('TLS connection failed; inspect diagnostics privately.');
return;
}
// Do not replay a write automatically after losing its response.
try {
rest.useConnection(connection, false);
} on ChilkatException {
print('Could not prepare the request.');
return;
}
var responseText = '';
final result = CkJsonObject();
result.strict = true;
try {
rest.addHeader('DataServiceVersion', '3.0;NetFx');
} on ChilkatException {
print('Could not prepare the request.');
return;
}
try {
rest.addHeader('MaxDataServiceVersion', '3.0;NetFx');
} on ChilkatException {
print('Could not prepare the request.');
return;
}
try {
rest.addHeader('Content-Type', 'application/json');
} on ChilkatException {
print('Could not prepare the request.');
return;
}
try {
rest.addHeader('Accept', 'application/json;odata=minimalmetadata');
} on ChilkatException {
print('Could not prepare the request.');
return;
}
var nextPartition = '';
var nextRow = '';
final seen = CkHashtable();
final marker = CkJsonObject();
var pageCount = 0;
var more = true;
while (more) {
if (pageCount >= 10000) {
print('Page limit reached; stop rather than loop indefinitely.');
return;
}
try {
rest.clearAllQueryParams();
} on ChilkatException {
print('Could not prepare the request.');
return;
}
try {
rest.addQueryParam('\$filter', 'PartitionKey eq \'customers-west\'');
} on ChilkatException {
print('Could not prepare the request.');
return;
}
try {
rest.addQueryParam('\$select', 'PartitionKey,RowKey,Address,NumberOfOrders');
} on ChilkatException {
print('Could not prepare the request.');
return;
}
try {
rest.addQueryParam('\$top', '100');
} on ChilkatException {
print('Could not prepare the request.');
return;
}
textCompare.clear();
textCompare.setString(nextPartition);
final sameText3 = textCompare.contentsEqual('', true);
if (!sameText3) {
try {
rest.addQueryParam('NextPartitionKey', nextPartition);
} on ChilkatException {
print('Could not prepare the request.');
return;
}
}
textCompare.clear();
textCompare.setString(nextRow);
final sameText4 = textCompare.contentsEqual('', true);
if (!sameText4) {
try {
rest.addQueryParam('NextRowKey', nextRow);
} on ChilkatException {
print('Could not prepare the request.');
return;
}
}
try {
responseText = rest.fullRequestNoBody('GET', resourcePath);
} on ChilkatException {
print('Request did not complete; inspect the target before retrying a write.');
return;
}
if (rest.responseStatusCode != 200) {
print('HTTP status: ${rest.responseStatusCode}');
print('Request ID: ${rest.responseHdrByName('x-ms-request-id')}');
// 404 is missing, 409 is conflict, and 412 is a stale ETag: none are success.
// Keep response bodies private. Reconcile uncertain writes before retrying.
return;
}
try {
result.load(responseText);
} on ChilkatException {
print('Expected well-formed JSON.');
return;
}
if (result.jsonTypeOf('value') != 4) {
print('Missing entity/table array.');
return;
}
final rowCount = result.sizeOfArray('value');
print('Rows on page: $rowCount');
pageCount++;
// Empty pages can still carry continuation tokens. Preserve all original query options.
nextPartition = rest.responseHdrByName('x-ms-continuation-NextPartitionKey');
nextRow = rest.responseHdrByName('x-ms-continuation-NextRowKey');
textCompare.clear();
textCompare.setString(nextPartition);
final sameText5 = textCompare.contentsEqual('null', true);
if (sameText5) {
nextPartition = '';
}
textCompare.clear();
textCompare.setString(nextRow);
final sameText6 = textCompare.contentsEqual('null', true);
if (sameText6) {
nextRow = '';
}
textCompare.clear();
textCompare.setString(nextPartition);
final sameText7 = textCompare.contentsEqual('', true);
textCompare.clear();
textCompare.setString(nextRow);
final sameText8 = textCompare.contentsEqual('', true);
if ((sameText7) && (!sameText8)) {
print('Malformed continuation: RowKey without PartitionKey.');
return;
}
more = false;
textCompare.clear();
textCompare.setString(nextPartition);
final sameText9 = textCompare.contentsEqual('', true);
if (!sameText9) {
more = true;
}
if (more) {
try {
marker.updateString('partition', nextPartition);
} on ChilkatException {
print('Could not prepare the request.');
return;
}
try {
marker.updateString('row', nextRow);
} on ChilkatException {
print('Could not prepare the request.');
return;
}
if (seen.contains(marker.emit())) {
print('Repeated continuation token; stop.');
return;
}
try {
seen.addStr(marker.emit(), 'seen');
} on ChilkatException {
print('Could not prepare the request.');
return;
}
rest.disconnect(10);
try {
connection.connect(endpoint.getAsString(), 443, true, 20000);
} on ChilkatException {
print('TLS reconnection failed.');
return;
}
try {
rest.useConnection(connection, false);
} on ChilkatException {
print('Could not prepare the request.');
return;
}
}
}
print('Listing complete.');
}