我有下面的代碼不工作。這是說PartitionKey和RowKey的值無法解析。我希望有一些能夠給我一些建議的專家。到目前爲止,我所依據的是一些建議,但仍然無法正常工作。c中的泛型和謂詞#
public class BaseTable
{
public string PartitionKey { get; set; }
public string RowKey { get; set; }
}
public abstract class AzureTableBase<T> : IAzureTable<T>
{
// This method gives the errors. The idea of this method is that instead of
// supplying the predicate you can just supply a value for partitionkey and
// rowkey as parameters. The problem is that it doesn't work and give the
// following syntax errors:
//
// Cannot resolve symbol PartitionKey
// Cannot resolve symbol RowKey
public virtual T Get<T>(string pkey, string rkey) where T : BaseTable
{
var a = this.Query.Where(u => u.PartitionKey == pkey && u.RowKey == rkey);
}
// Following method works:
public virtual T Get(Expression<Func<T, bool>> predicate)
{
return this.Query.Where(predicate).FirstOrDefault();
}
public virtual IQueryable<T> Query
{
get
{
TableServiceContext context = CreateContext();
return context.CreateQuery<T>(TableName).AsTableServiceQuery();
}
}
}
下面是我目前如何調用第二Get函數的例子:
SubTest = testTable.Get(u => u.PartitionKey == "XX" & u.RowKey == "YY")
我要的是能夠調用它是這樣的:
SubTest = testTable.Get("XX","YY")
實際的錯誤信息會有幫助。沒有更多的信息很難說。我不知道'this.Query'的類型是什麼,因爲它似乎是導致問題的原因。 – asawyer
什麼是「這個」?是「獲取」BaseTable的一種方法嗎? –
將this.Query定義爲IEnumerable? –