我有一堆主键 - 数万个,我想检索它们关联的表实体。所有行键都是空字符串。我知道这样做的最好方法是一一异步地查询它们。它看起来很快,但理想情况下我想在一个事务中将几个实体捆绑在一起。使用新的存储客户端,我有以下代码失败:
var sample = GetSampleIds(); //10000 pks
var account = GetStorageAccount();
var tableClient = account.CreateCloudTableClient();
var table = tableClient.GetTableReference("myTable");
//I'm trying to get first and second pk in a single request.
var keyA = sample[0];
var keyB = sample[1];
var filterA = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, keyA);
var filterB = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, keyB));
//filterAB = "(PartitionKey eq 'keyA') or (PartitionKey eq 'keyB')"
var filterAB = TableQuery.CombineFilters(filterA, TableOperators.Or, filterB);
var query = new TableQuery<TweetEntity>().Where(filterAB);
//Does something weird. I thought it might be fetching a range at one point.
//Whatever it does it doesn't return. Expected the following line to get an array of 2 items.
table.ExecuteQuery(query).ToArray()
// replacing filterAB in query with either filterA or filterB works as expected
示例总是显示 CombineFilters 在 PK 和 RK 上工作,但这对我没有用。我假设这是不可能的。
问题
是否可以通过 PK 将实体捆绑在一起?我知道过滤器的最大长度是 15,但是当您获取 10,000 个项目时,即使是 2 也是一个潜在的改进。另外,说明书在哪里?在任何地方都找不到合适的文档。例如,用于 CombineFilters 的 MSDN 是一个基本的 shell,包含了智能感知提供的较少信息。