我在Azure中有一个包含以下主键和行键的存储表(不是真的,只是一个示例),并将整个表作为TableEntities列表检索:
“PartitionKey”,“00”
“PartitionKey”,“01”
“PartitionKey”,“10”
“PartitionKey”,“11”
“PartitionKey”,“20”
“PartitionKey”,“21”
当我像这样查询列表时:
var myItem =
(from item in list
where item.RowKey == "00"
select item).FirstOrDefault();
myItem返回NULL。如果查询RowKey==“01”,情况也是如此。
但是当我单独通过行键查询任何没有前导“0”的字符串时,我会得到预期的结果。此外,如果我使用任何PartitionKey进行查询,并且RowKey具有前导“0”:
var myItem =
(from item in list
where item.PartitionKey == "partitionkey" && item.RowKey == "00"
select item).FirstOrDefault();
我也会得到预期的结果。
如果Azure表存储中的行键是字符串,为什么一个前导“0”的字符串有关系呢?
有没有其他人碰到过这个?如果有,是不是一个窃听器?
有没有其他人碰到过这个?如果有,是不是一个窃听器?
根据您的描述,在MyItem
返回NULL时,列表中似乎没有合适的实体。您可以尝试输出列表中的实体
foreach (var item in list)
{
Console.WriteLine("{0}, {1}", item.PartitionKey, item.RowKey,);
}
我用下面的代码测试,它在我这边正常工作。我不能重复你提到的问题
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();
测试结果: