Reputation: 609
We are having a problem with querying data from the .NET client. This is the code we are running:
var query = $"SELECT d FROM default AS d where type='{type}'"; var result = Bucket.Query(query);
the issue is that whilst result.Rows is returning the correct number of rows, they do not contain any data. Upon doing a Buck.Query we can see that what is actually being returned is a list of entities of type 'd' not a list of ContentBlocks. it seem that due to this JSON.NET is unable to deserialize it back to the correct type.
Any thoughts on this?
Upvotes: 0
Views: 151
Reputation: 2481
Update: There is actually a much simpler solution. All you have to do is change the nickel query as follows:
SELECT default.* FROM default WHERE type='{type}'
This will return the documents as an array of JSON objects directly, rather than adding them as sub-properties. This way the SDK will be able to deserialize the result correctly.
Original answer:
There seems to be a bug with the current implementation of the QueryClient's default deserialization in the .NET SDK. I've emailed the person maintaining it to see if this is something they're working to fix already, or a new issue.
In the mean time, you can work around this by getting the document ids with the N1QL query and then retrieving the documents themselves in bulk as a key-value operation:
var query = "select meta(default).id as docId from default where type='{type}'";
var res = _bucket.Query<dynamic>(query);
var docs = _bucket.Get<ContentBlock>(res.Rows.Select(r => r["docId"].Value as string).ToList())
.Select(r => r.Value);
There is probably also a way to work around it with a custom serializer, but that's going to be more work, and also harder to remove in the future when you want to go back to using Query normally.
Upvotes: 1