.NET Guid with Linq2Couchbase Where

Assume Thing is a class with a Guid ID:

var result = from c in bucketContext.Query<'Thing>() select c;

Works fine and deserializes the Id into a Guid. However, if I try:

var result = from c in bucketContext.Query<'Thing>() where c.ID == SomeGuid select c;

It fails, and I have to resort to using something like this:

var result = from c in bucketContext.Query<'Thing>() where c.ID.ToString() == “8836bea2-a6ae-43c0-bd09-947515647610” select c;

It would be nice if I could just use the Guid without having to convert to a string.

@ACobbler -

This looks like a potential bug - any chance you can post the generated N1QL query?

Thanks,

Jeff

I think that we missed handling GUID constants here:

Simple fix, though.

Brant

1 Like

Would love to help out here, but I’m fairly new to the library. What’s the best way to get the generated N1QL query from outside the library? A quick poked around the libary and I saw there was and internal class QueryParserHelper, but I didn’t see anything else.

However, per Brant’s suggestion I added the following: the VisitConstant Method he mentioned and that fixed the issue:

        else if (namedParameter.Value is Guid)
        {
            _expression.AppendFormat("'{0}'", namedParameter.Value.ToString());
        }

@ACobbler -

Cool! Could you push a pull request?

Thanks,

Jeff

Will do so later this evening! Thanks for the quick support btw!

1 Like