【问题标题】:How to query by partitionkey in Azure Table Storage?如何在 Azure 表存储中按分区键查询?
【发布时间】:2010-02-09 19:01:19
【问题描述】:

我有如下TableServiceContext 类的书,我想通过partitionKey 查询表Books,请忽略这个事实 我使用分区键作为书名,这只是为了我的学习方便

   public class BookDataServiceContext: TableServiceContext
        {

            public BookDataServiceContext(string baseAddress, StorageCredentials credentials)
                : base(baseAddress, credentials)
            {
            }

            public IQueryable<Book> Books
            {
                get
                {
                    return this.CreateQuery<Book>("Books");
                }
            }

            public void AddMessage(string name, int value)
            {
                this.AddObject("Books", new Book {PartitionKey=name, BookName = name, BookValue = value});
                this.SaveChanges();
            }

            public Book GetBookByPartitionKey(Guid partitionKey)
            {
                var qResult = this.CreateQuery<Book>("Books");
    This doesnt work ---->           // qResult = qResult.Where(e => (e.PartitionKey.CompareTo(partitionKey)==0));

            } 
}

我在最后一行收到“无法将类型 'System.Linq.IQueryable' 隐式转换为 'System.Data.Services.Client.DataServiceQuery'。存在显式转换(您是否缺少演员表?)”。

任何帮助将不胜感激!

【问题讨论】:

    标签: azure createquery


    【解决方案1】:

    qResult 已经被编译器分配了一个类型。您正在尝试将其重新分配给其他类型,但这是不允许的。

    试试这个

    var someOtherName = qResult.Where(e => (e.PartitionKey.CompareTo(partitionKey)==0));
    

    编辑:您的 Books 属性似乎是错误的类型。

    public DataServiceQuery<Book> Books
    {
        get
        {
            return this.CreateQuery<Book>("Books");
        }
    }
    
    public Book GetBookByPartitionKey(string partitionKey)
    {
        var qResult = Books.Where(e => (e.PartitionKey.CompareTo(partitionKey)==0));
    }
    

    【讨论】:

      猜你喜欢
      • 2016-08-05
      • 1970-01-01
      • 2014-07-27
      • 2019-04-09
      • 2017-09-30
      • 2013-09-17
      • 2014-02-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多