Cannot get expression with "IN" operator to work in .Net Lite query

I have a data structure where I need to get the result of a query like this (in N1QL):

SELECT * FROM data 
WHERE type='ObservationType' AND "2" in locationtypes

In .Net lite I have this code:

if (!string.IsNullOrEmpty(locationType))
{
       _condition = _condition.And(Expression.String(locationType).In(Expression.Property("locationtypes")));
}

… but I get a: System.NotSupportedException has been thrown. I tried with this as well:

       _condition = _condition.And(Expression.String(locationType).In(Expression.Value(Expression.Property("locationtypes"))));

Same error :frowning:

How can I make the query understand that I want to use the “locationtypes” property?

This is a sample output from the N1QL query:

      "locationtypes": [
        "2"
      ],

… or:

      "locationtypes": [
        "4",
        "5"
      ],
  let searchQuery = QueryBuilder
            .select(SelectResult.expression(Meta.id))
            .from(DataSource.database(db))
            .where(Expression.property("type").equalTo(Expression.string("ObservationType"))
                .and( ArrayFunction.contains(Expression.property("locationtypes"), value: Expression.int(2))))

Ok, so I can’t use the “in” operator :slight_smile:

For some reason code like the above does not seem to return the data I expect. Looking in the debugger the _condition is set to:

{[QueryCompoundExpression] => ["AND",["=",[".type"],"ObservationType"],["ARRAY_CONTAINS()",[".locationtypes"],"2"]]}

And if I understand the notation then that should be correct? So I guess I need to verify that the sync is working the way I expect it and the field with values (set from the server) really are in the local db :wink:

Thanks!

Ahhh… - and YES, an update of the data in that database instance wasn’t updated :blush:

It works like a charm :+1::pray:

1 Like