Reputation: 403
I have a storage table in Azure with the following primary and row keys (not really, just an example) and retrieve the whole table as a list of TableEntities:
"partitionkey", "00"
"partitionkey", "01"
"partitionkey", "10"
"partitionkey", "11"
"partitionkey", "20"
"partitionkey", "21"
When I query the list like so:
var myItem =
(from item in list
where item.RowKey == "00"
select item).FirstOrDefault();
myItem returns null. The same is true if I query for RowKey == "01".
But when I query by RowKey alone with any string which does NOT have a leading "0", I get the expected result. Also, if I query using any PartitionKey and the RowKey HAS a leading "0":
var myItem =
(from item in list
where item.PartitionKey == "partitionkey" && item.RowKey == "00"
select item).FirstOrDefault();
I will also get the expected result.
If RowKeys in Azure Table Storage are strings, why does a string with a leading "0" matter?
Has anybody else run into this and if so, is it a bug?
Upvotes: 0
Views: 1205
Reputation: 24549
Has anybody else run into this and if so, is it a bug?
According to your description, it seems that there is no suitable entity in the list when
myItem
returns null. You could try to output the entities in the list
foreach (var item in list)
{
Console.WriteLine("{0}, {1}", item.PartitionKey, item.RowKey,);
}
I test with following code, it works correctly on my side. I can't reproduce the issue you mentioned
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("storage connectionstring");
// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
// Create the CloudTable object that represents the "test" table.
CloudTable table = tableClient.GetTableReference("test");
TableQuery<TableEntity> query = new TableQuery<TableEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey",QueryComparisons.Equal, "partitionkey"));
var list = table.ExecuteQuery(query);
var myItem = (from item in list
where item.RowKey == "00"
select item).FirstOrDefault();
Test result:
Upvotes: 0