简体   繁体   中英

Azure Cosmos DB Table API - LIST Generic

We recently move form Doc DB to using the table api with COSMOS DB on Azure. We wanted a generic list method like:

public async Task<IEnumerable<T>> ListEntityAsync(Expression<Func<T, bool>> predicate)
    {
        // Filter against a property that's not partition key or row key
        TableQuery<T> query = new TableQuery<T>().Where(predicate);

        var results = _table.ExecuteQuery(query);

        return results.ToList();
    }

but we get invalid cast exceptions as the Where clause returns an IQueryable and the execute method needs TableQuery.

Any ideas would be appreciated! Thanks!

You can convert an IQueryable instance generated by the Where clause to TableQuery instance using the AsTableQuery extension method provided by the SDK, under the Queryable namespace (below)

References

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