Uploaded image for project: 'Couchbase .NET client library'
  1. Couchbase .NET client library
  2. NCBC-2218

IQueryResult.Rows property is null even when query returns results.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 3.0.0-beta.1
    • library
    • None
    • .Net Core 3.0.1
    • 1

    Description

      I've got a bucket called "bugtest". I insert a document, and then I write a query to retrieve the document. When I run QueryAsync<T>, the IGetResult Rows property returns null. However, when you treat the IGetResult object like an IQueryable type and perform a LINQ operation like Select(), etc, you get results back. 

       

      Example test classes: 

      public class TestData    {        
          public string StringTest { get; set; }        
          public int IntTest { get; set; }        
          public Dictionary<string, int> DictTest { get; set; }    
      }
      public class BugTestResult    
      {        
          public TestData BugTest { get; set; }    
      }
      

      Example code showing the issue and workaround (I suggest using the debugger in a console application)

       

      var connString = "couchbase://127.0.0.1";
                  var options = new ClusterOptions();             
                  options.WithBucket("bugtest")            
                         .WithCredentials("Administrator", "danger")             
                         .WithServers(connString);
                  var cluster = new Cluster(connString, options);
                  var bucketResult = cluster.BucketAsync("bugtest");
                  bucketResult.Wait();
                  var collection = bucketResult.Result.DefaultCollection();
                  var testData = new TestData()            {                
                      StringTest = "test",                
                      IntTest = Int32.MaxValue,
                      DictTest = new Dictionary<string, int>(){                               
                          {"key1", 1},
                          {"key2", 2},
                          {"key3", 3}
                      }
                  };
                  var key = "test:mydoc";
                  collection.InsertAsync(key, testData);
                
                  //what happens when we query for it? 
                  const string query = "SELECT * FROM bugtest USE KEYS [\"test:mydoc\"]";
                  var queryTask = cluster.QueryAsync<BugTestResult>(query);
                  queryTask.Wait();
                  var qr = queryTask.Result;
                  if (qr.Rows == null)            {                Console.WriteLine("Should have had 1 result, not null");            }
                  //...but then if I do a select on *qr*, I get results. 
                  //query workaround
                  var qrSelect = qr.Select(x => x).ToList(); //this returns results? Why? because qr implements IQueryable<T>? 
                  Console.WriteLine($"qrSelect returned {qrSelect.Count()} rows");
                  //...now what is that item? 
                  var firstQueryResult = qrSelect.First();
                  Console.WriteLine(firstQueryResult);
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            jmorris Jeff Morris
            alexcavnar Alex Cavnar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty