考虑我的情景。我有大约200个分区,每个分区有大约1000个rowkeys(实体)甚至更多。因此,当我进行任何查询获取最后一个分区的记录(以“z”开头)时,它不会返回任何结果。
以下是示例查询 -
audioRecordServiceContext.QueryableEntities
.Where(p => p.PartitionKey == channel &&
p.IsDedication == true &&
p.IsBroadcast == true &&
p.BroadcastTime >= time &&
p.BroadcastTime < time.AddHours(1))
.ToList();
当我从初始字母表开始传递一个频道时,它会正确地返回实体,但是当我给出一个以probabaly“Z”开头的频道时,它不会返回任何实体。
知道如何解决这个问题吗?
编辑:
查询字符串
http://sampleservice/devstoreaccount1/AudioRecord()?$filter=Username eq 'username'
查询的提琴手回复
**HTTP/1.1 200 OK
Cache-Control: no-cache
Transfer-Encoding: chunked
Content-Type: application/atom+xml;charset=utf-8
Server: Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 06dff157-f693-49a6-ade7-b7165a4d3dfb
x-ms-version: 2009-09-19
x-ms-continuation-NextPartitionKey: 1!16!QWZnaGFuaXN0YW4-
x-ms-continuation-NextRowKey: 1!48!YTZiOGQxZmYtYjNkYy00NDEyLTk2YmItZTViNmUyMWNhYzJi
Date: Wed, 04 Sep 2013 12:19:03 GMT**
答案 0 :(得分:3)
这是一个示例代码,根据传递的查询获取所需数量的实体;在我的环境中,这将返回超过10,000个实体,并自动处理延续令牌。我不是100%肯定它正在使用的SDK版本,但它应该使用1.7。这里的神奇之处在于AsTableServiceQuery,它是SDK提供的扩展方法,可以执行分页和自动重试。
_tableName变量包含我的表的名称。
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
TableServiceContext serviceContext = tableClient.GetDataServiceContext();
var partitionQuery =
(from e in serviceContext.CreateQuery<MyData1>(_tableName)
where e.PartitionKey.CompareTo("15") >= 0 && e.PartitionKey.CompareTo("39") <= 0
select new MyData1()
{
PartitionKey = e.PartitionKey,
RowKey = e.RowKey,
Timestamp = e.Timestamp,
Message = e.Message,
Level = e.Level,
Severity = e.Severity
}
).AsTableServiceQuery();
return partitionQuery.ToList<MyData1>();
上面的代码依赖于一个名为MyData1的类,定义如下:
public class MyData1 : TableServiceEntity
{
public string Message { get; set; }
public string Level { get; set; }
public string Severity { get; set; }
}
希望这会有所帮助......