N1QL Query result return POCO objects with all properties null

Hello, I have the following N1QL query from beer-sample bucket:

public IEnumerable<Beer> Select(IQueryRequest n1qlQuery)
    {
        var bc = ClusterHelper.GetBucket(CouchbaseConfigHelper.Instance.Bucket);
        var results = bc.Query<Beer>(n1qlQuery);
       
        return results.Rows;
    }

I get a correct number of results but every property in all POCO object is null. if I use dynamic object instead I get a valid return.

Here is the Beer class
public class Beer
{

    public string Name { get; set; }

    public int Abv { get; set; }

    public int Ibu { get; set; }

    public int Srm { get; set; }

    public int Upc { get; set; }

    public string Type { get; set; }

    [JsonProperty("brewery_id")]
    public string BreweryId { get; set; }

    public string Description { get; set; }

    public string Style { get; set; }

    public string Category { get; set; }
}

I’d appreciate someones help on this one.

Thank you!

@dev2201

Can you provide the N1QL query itself that you are using? That may help us diagnose the problem.

That said, I have a suspicion. If you are using

SELECT * FROM `beer-sample` ...

try changing that to

SELECT `beer-sample`.* FROM `beer-sample` ...

If you don’t preface the asterisk with the name of the bucket, then it wraps the result in an extra object with the bucket name as a property. This will confuse the deserializer.

Brant

3 Likes