private static void ReadByPK() { var connectionString = "your_connection_string"; var tableName = "USERSAMPLE"; var CSAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(connectionString); var CTClient = CSAccount.CreateCloudTableClient(); var CTable = CTClient.GetTableReference(tableName); var query = new Microsoft.WindowsAzure.Storage.Table.TableQuery <User>(); query.FilterString = Microsoft.WindowsAzure.Storage.Table.TableQuery.GenerateFilterCondition("PartitionKey", Microsoft.WindowsAzure.Storage.Table.QueryComparisons.Equal, "GROUP4"); var res = new System.Collections.Concurrent.ConcurrentBag <User>(); System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); Microsoft.WindowsAzure.Storage.Table.TableContinuationToken continuationToken = null; do { var page = CTable.ExecuteQuerySegmentedAsync(query, continuationToken).Result; continuationToken = page.ContinuationToken; if (page.Results != null) { foreach (var obj in page.Results) { res.Add(obj); } } }while (continuationToken != null); stopwatch.Stop(); Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(res)); Console.WriteLine("Count >>" + res.Count); Console.WriteLine(stopwatch.Elapsed.ToString()); }
} // CustomerDataServiceContext /// <summary> /// Loads the customer based upon their customer key /// </summary> internal Customer Select(Guid customerId) { string filter1 = Microsoft.WindowsAzure.Storage.Table.TableQuery.GenerateFilterCondition("PartitionKey", Microsoft.WindowsAzure.Storage.Table.QueryComparisons.Equal, customerId.ToString().ToLower()); string filter2 = Microsoft.WindowsAzure.Storage.Table.TableQuery.GenerateFilterCondition("RowKey", Microsoft.WindowsAzure.Storage.Table.QueryComparisons.Equal, customerId.ToString().ToLower()); string filter = Microsoft.WindowsAzure.Storage.Table.TableQuery.CombineFilters(filter1, Microsoft.WindowsAzure.Storage.Table.TableOperators.And, filter2); Microsoft.WindowsAzure.Storage.Table.TableQuery <Customer> tableQuery = new Microsoft.WindowsAzure.Storage.Table.TableQuery <Customer>().Where(filter); foreach (Customer item in cloudTable.ExecuteQuery(tableQuery)) { return(item); } return(null); }
} // CustomerDataServiceContext /// <summary> /// Loads the customer based upon their customer key /// </summary> internal ExceptionLog Select(Guid exceptionLogId) { string filter1 = Microsoft.WindowsAzure.Storage.Table.TableQuery.GenerateFilterCondition("PartitionKey", Microsoft.WindowsAzure.Storage.Table.QueryComparisons.Equal, exceptionLogId.ToString().ToLower()); string filter2 = Microsoft.WindowsAzure.Storage.Table.TableQuery.GenerateFilterCondition("RowKey", Microsoft.WindowsAzure.Storage.Table.QueryComparisons.Equal, exceptionLogId.ToString().ToLower()); string filter = Microsoft.WindowsAzure.Storage.Table.TableQuery.CombineFilters(filter1, Microsoft.WindowsAzure.Storage.Table.TableOperators.And, filter2); Microsoft.WindowsAzure.Storage.Table.TableQuery<ExceptionLog> tableQuery = new Microsoft.WindowsAzure.Storage.Table.TableQuery<ExceptionLog>().Where(filter); foreach (ExceptionLog item in cloudTable.ExecuteQuery(tableQuery)) { return item; } return null; }