C# SDK travel-sample

https://docs.couchbase.com/dotnet-sdk/current/n1ql-queries-with-sdk.html
row.name always returned null… sample code is wrong;

public async void PrintTenAllAsync()
{
const string query = “SELECT * FROM travel-sample LIMIT 10”;

var result = await _bucket.QueryAsync<dynamic>(query);
foreach(var row in result.Rows)
{
    Console.WriteLine(row.name);
}

}

------------THIS CODE CORRECT----------------

public async void PrintTenAllAsync()
{
const string query = “SELECT * FROM travel-sample as ts LIMIT 10”;

var result = await _bucket.QueryAsync<dynamic>(query);
foreach(var row in result.Rows)
{
    Console.WriteLine(row.ts.name);
}

}

Yes, it looks like there’s a missing reference to travel-sample there. I filed DOC-6152 to get it fixed, thanks!

@smartanaliz -

Hi thanks for reporting, your suggestion will definitely work, but it was intended the alias be prepended to the wild card character: SELECT ts.* FROM travel-sample as ts LIMIT 10; in the query itself. This will omit the alias from each row:

[
 {
    "callsign": "MILE-AIR",
    "country": "United States",
    "iata": "Q5",
    "icao": "MLA",
    "id": 10,
   "name": "40-Mile Air",
   "type": "airline"
  }, ...

And then the foreach should work as intended:

var result = await _bucket.QueryAsync<dynamic>(query);
foreach(var row in result.Rows)
{
    Console.WriteLine(row.name);
}

-Jeff

1 Like