Are Linq2couchbase queries case-sensitive?

I am using Linq2Couchbase to retrieve the data. Today, I spent a considerable time on one query where I have to use Where<> condition.(Code Below)

foreach (var i in queryTour.Itineraries)
                {
var querySch = (from s in db.Query<Schedule>()
                                    where s.type == "schedule" && s.tour == queryTour.Name
                                    select s).ToList();

I have created the CouchBase documents with the fields’ names starting with Capital letters ( eg: Name, Tour etc). In the above query, first I was trying “s.Tour” and the Linq was not at all fetching any data. After long time of try by rearranging the queries and other ways, I thought like will try changing the naming convention( because I found that the entries in beer-sample bucket had field names in small letters), and to my surprise , the query worked.

I donot know whether I am missing any basic knowledge , but it looked strange when it worked as soon as changed the field names. Can any one tell me the reason ?

@nithisha

Yes, N1QL queries against JSON data are case sensitive. While SQL is case-insenstive for column names, N1QL must be case-sensitive for property names. This is because of the JSON nature of the data. In JSON it’s possible to include both “type” and “Type” as property names in the same document.

That being said, normally Linq2Couchbase handles the case for you. It uses the serialization settings configured in the Couchbase SDK to determine how to capitalize the property names in the generated N1QL query. By default, this means that Pascal-cased property names (i.e. “Type”) are converted to Camel-case (i.e. “type”) without you needing to do anything special.

Can you answer the following questions, which might help me diagnose your issue?

  1. Can you provide the code for your Schedule POCO?
  2. Have you implemented a custom serializer/deserializer?
  3. If not, have you changed the default settings for the Newtonsoft.Json serializer/deserializer in the Couchbase SDK configuration?

Thanks,
Brant

1 Like