Reputation: 3035
I'm trying to create a generic method to read only some properties of azure table. TO create this Im making use of TableQuery, but some how im unable to pass Filter condition
public IEnumerable<T1> ExecuteQuery<T, T1>(Expression<Func<T,bool>> predicate)
where T : TableEntity, IDomainData, new()
where T1 : new()
{
Type typeParameterType = typeof(T);
CloudTable tableReference = tableClient.GetTableReference(typeParameterType.Name);
var query = new TableQuery<T>()
{
FilterString = predicate.Body.ToString(),
SelectColumns = typeof(T1).GetListOfPropertyNames()
};
query = query.Where(predicate).AsTableQuery(); ==> Throws error Object reference error
return tableReference.ExecuteQuery(query) as List<T1>;
//return tableReference.ExecuteQuery<T, T1>(query,EntityAdapter.AdapterResolver<T1>);
}
Is there where to pass Filterstring to TableQuery and execute the TableQuery with azure table instance
Upvotes: 1
Views: 1422
Reputation: 1269
If you are trying to get a subset of properties from the table along with a filter condition, you would have to specify it using the Select and Where clause as follows -
TableQuery<T> query = new TableQuery<T>().Select(new List<string>() { "prop1", "prop2" }).Where("filter string");
List<T> result = currentTable.ExecuteQuery(query).ToList();
Also, there are helper methods in the storage client library that you can use to construct the filter strings. See TableQuery.GenerateFilterCondition.
Upvotes: 1