简体   繁体   中英

How to make use of new TableQuery<T> in azure table storage

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM