2

私は本のために次の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'に暗黙的に変換できません。明示的な変換が存在します(キャストがありませんか?)」というメッセージが表示されます。

どんな助けでもありがたいです!

4

1 に答える 1

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));
}
于 2010-02-09T19:10:11.843 に答える