C# SDK 2.x Migration to 3.x --> IViewResult<T> Query<T>(IViewQuery query) to using QueryAsync<T>(string statement)


Trying to figure out how to migrate the use of Query from 2.x to 3.x

I am noticing that 2.x method uses IViewQuery, where 3.x is just a string.

IViewResult<T> Query<T>(IViewQuery query)

Task<IQueryResult<T>> QueryAsync<T>(string statement)

Need a way to convert the IViewQuery parameter from 2.x into a string statement that 3.x can use in the parameter.

What is the best route/method in doing this?

Example 2.x Usage:

  var all = CouchBaseClient.Query<dynamic>("AccountAction", CouchBaseClient.CreateQuery("AccountAction", "type", "type").
                   StartKey(new object[] { "qbo" }).
                    EndKey(new object[] { "qbo", new { } })
            if (!all.Success)
                throw all.Exception;

            return all.Rows.Select(q => q.Id.Replace("_qbo", "")).ToArray();


Brian Davis

@Brian_Davis -

Your actually calling the wrong method for a View query! Try using the IBucket.ViewQueryAsync method instead.

 var result = await bucket.ViewQueryAsync<object, int>("beer", "by_location", options =>

In short, the View API was moved to the IBucket interface while N1QL, Analytics and Search are located in the ICluster interface.


1 Like