2014-01-25 91 views
1

我很遗憾,如何在Azure表存储中实现此方法。 (注意:我对它很新颖)如何查询Azure表存储中的多个分区键?

public IList<string> GetUserConnections(int[] userIds) 
{ 
    string[] result = userIds.Select(x => x.ToString()).ToArray(); 
    var queryResult = _table.CreateQuery<ConnectionEntity>().Where(n =>  result.Contains(n.PartitionKey)); 
    return queryResult.Select(n => n.RowKey).ToList(); 
} 

我在执行查询时遇到错误。

An exception of type 'System.NotSupportedException' occurred in 
Microsoft.WindowsAzure.Storage.dll but was not handled in user code 

Additional information: The method 'Contains' is not supported 

这是我的ConnectionEntity。

public class ConnectionEntity:TableEntity 
{ 
    public ConnectionEntity() 
    { 

    } 

    public ConnectionEntity(int userId, string connectionId) 
    { 
     this.PartitionKey = userId.ToString(); 
     this.RowKey = connectionId; 
    } 
} 

是否可以做一个Contains操作符?我似乎无法找到有关此类查询的文档。我应该考虑对分区键进行批量查询吗?

+0

你是否设法做到底?我现在有一个循环结合他们: 'TableQuery.CombineFilters(expression,operatorString:“或”,filterB:nextPartitionKey)“,但我不能用它作为IQueryable ,这是更可取的。我想我会抓住更多的数据,像Nathan所暗示的那样。 – Matthew

回答

0

看着你的代码我认为唯一能做的就是阅读所有类型的记录,并对本地集合进行LINQ查询。只要少于几千条这种类型的记录,这将非常快速,并且取决于这些记录被修改的频率,您可以使用某种本地缓存快速地进行后续查询。如果您有太多的此类记录可行,则可能需要重新考虑您的分区策略或应用程序的这部分设计,以便它可以查询较小的数据子集(可能通过某个分区键)。

相关问题