次のコードは動作しません。 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のメソッドですか? –
これは、IEnumerableとして定義されていますか? –