如何在Azure表存储中通过partitionkey进行查询?
我有以下用于图书的 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’。显式转换存在(您是否缺少演员表?)”在最后一行。
任何帮助将不胜感激!
I have the following TableServiceContext class for books, I want to query the table Books by the partitionKey, please ignore the fact that
I'm using the partition key as the book name, this is just for my learning sakes
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));
}
}
I get a "Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Data.Services.Client.DataServiceQuery'. An explicit conversion exists (are you missing a cast?)" on that last line.
Any help will be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
qResult
已由编译器分配了一个类型。您试图将其重新分配给不同的类型,但这是不允许的。试试这个
编辑:您的图书属性似乎类型错误。
qResult
is already assigned a type by the compiler. You're trying to re-assign it to a different type, but that isn't allowed.Try this
Edit: It looks like your Books property is the wrong type.