Very simple N1QL sentence is returning empty objects when type is specified

Hello.

We’re at the early stage of developing an application and when querying a bucket with a very simple N1QL sentence the result contains empty rows. I mean, there are 3 objects to retrieve with that QUery and the result object contains 3 rows but each one of them are with their empty properties.

The query is in C#, using the latest SDK 2.2.5 and 4.0 Server version.

This is the query that returns a correct number of Rows but with empty objects.

var N1QL = “select * from aiberouting_internal where type=‘tenantconfig’”;
var result = couchbaseBucket_internal.Query(N1QL);

If I change this to dynamic type then the objects are full, but it’s very annoying for me working with the dynamic result when I can use the exact type. The dynamic result also includes an object with a property named as the bucket name, may be this could give a tip about the problem? I haven’t found more documentation about this and I’m really missing.

var result = couchbaseBucket_internal.Query(N1QL);

<< Sorry, I had to delete this image because new users can only post one image! >>

<< The object is retrieved full:
{ “aiberouting_internal”: { “active”: true, “licensed_channels”: 10, “licensed_users”: 20, “tenant”: “DATA”, “tenant_id”: “DATA1”, “type”: “tenantconfig” }} >>

This is the object in the bucket as shown via Web Manager:
{
“tenant”: “DATA”,
“tenant_id”: “DATA1”,
“licensed_users”: 20,
“licensed_channels”: 10,
“active”: true,
“type”: “tenantconfig”
}

This is the class definition:

public class TenantConfig
{
public string tenant { get; set; }
public string tenant_id { get; set; }
public int licensed_users { get; set; }
public int licensed_channels { get; set; }
public bool active { get; set; }
public string type { get; set; }
}

As a workaround… Is there any way to convert the dynamic object to the .NET class after retrieving it with the dynamic succesful query?

Thank you.

I’ve found that specifying all the fields in the query the result is correcly deserialized (select tenant, tenant_id, etc)…

my question is… is there any way to do this without having to specify all the fields? it’s a little tedious when adding fields.

Thank you.

@pasamelo -

Are you using the default serializer? I suspect that the mapping between your type properties and the N1QL response are not matching. You may need to explicitly map your fields using the [DataMember(Name="foo")] attribute, however assuming your document and poco fields match, this should be done implicitly - if you are using the default serializer.

Can you post the raw N1QL response returned (use Fiddler, Charles,etc)?

-Jeff

@pasamelo

Try changing your query to this:

select aiberouting_internal.* from aiberouting_internal where
type=‘tenantconfig’

The way the result objects are nested in JSON can change depending on the
identifier in front of the *. Without the identifier everything will be
wrapped in a property the same as the name of your bucket.

Brant

2 Likes

Thank you, that fixed the issue!!

It would be nice to update the SDK documentation with some more samples like this.

I thought about it at first but I discarded it cause the objects were inserted in database with instances created from the same class. Finally it’s just a syntax problem!

Thank you!