diff --git a/src/CouchDB.Driver/Translators/ConstantExpressionTranslator.cs b/src/CouchDB.Driver/Translators/ConstantExpressionTranslator.cs index 895087c..63a7ce3 100644 --- a/src/CouchDB.Driver/Translators/ConstantExpressionTranslator.cs +++ b/src/CouchDB.Driver/Translators/ConstantExpressionTranslator.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Linq.Expressions; @@ -41,16 +42,21 @@ protected override Expression VisitConstant(ConstantExpression c) VisitIEnumerable(c.Value as IList); else if (c.Value is IList) VisitIEnumerable(c.Value as IList); - else if(c.Value is IList) + else if (c.Value is IList) VisitIEnumerable(c.Value as IList); else if (c.Value is IList) VisitIEnumerable(c.Value as IList); else if (c.Value is IList) VisitIEnumerable(c.Value as IList); - else if(c.Value is IList) + else if (c.Value is IList) VisitIEnumerable(c.Value as IList); + else if (c.Value is Guid) + _sb.Append(JsonConvert.SerializeObject(c.Value)); else - throw new NotSupportedException(string.Format("The constant for '{0}' is not supported", c.Value)); + { + Debug.WriteLine($"The constant for '{c.Value}' not ufficially supported."); + _sb.Append(JsonConvert.SerializeObject(c.Value)); + } break; default: _sb.Append(c.Value); @@ -85,7 +91,7 @@ string VisitConst(object o) case TypeCode.String: return $"\"{o}\""; case TypeCode.Object: - throw new NotSupportedException(string.Format("The constant for '{0}' is not supported", o)); + throw new NotSupportedException(string.Format("The constant for '{0}' is not supported", o)); default: return o.ToString(); } diff --git a/tests/CouchDB.Driver.UnitTests/Find/Find_Selector.cs b/tests/CouchDB.Driver.UnitTests/Find/Find_Selector.cs index fadc4ff..c334c4f 100644 --- a/tests/CouchDB.Driver.UnitTests/Find/Find_Selector.cs +++ b/tests/CouchDB.Driver.UnitTests/Find/Find_Selector.cs @@ -24,9 +24,9 @@ public void ToList_EmptySelector() [Fact] public void ComplexQuery() { - var json = rebels.Where(r => - r.Age == 19 && - (r.Name == "Luke" || r.Name == "Leia") && + var json = rebels.Where(r => + r.Age == 19 && + (r.Name == "Luke" || r.Name == "Leia") && r.Skills.Contains("force")).ToString(); Assert.Equal(@"{""selector"":{""$and"":[{""age"":19},{""$or"":[{""name"":""Luke""},{""name"":""Leia""}]},{""skills"":{""$all"":[""force""]}}]}}", json); } @@ -65,5 +65,13 @@ public void Enum() var json = rebels.Where(r => r.Species == Species.Human).ToString(); Assert.Equal(@"{""selector"":{""species"":0}}", json); } + [Fact] + public void GuidQuery() + { + var guidString = "83c79283-f634-41e3-8aab-674bdbae3413"; + var guid = Guid.Parse(guidString); + var json = rebels.Where(r => r.Guid == guid).ToString(); + Assert.Equal(@"{""selector"":{""guid"":""83c79283-f634-41e3-8aab-674bdbae3413""}}", json); + } } } diff --git a/tests/CouchDB.Driver.UnitTests/_Models/Rebel.cs b/tests/CouchDB.Driver.UnitTests/_Models/Rebel.cs index 0d46269..c75e1b8 100644 --- a/tests/CouchDB.Driver.UnitTests/_Models/Rebel.cs +++ b/tests/CouchDB.Driver.UnitTests/_Models/Rebel.cs @@ -11,6 +11,7 @@ public class Rebel : CouchDocument public string Surname { get; set; } public int Age { get; set; } public Species Species { get; set; } + public Guid Guid { get; set; } public List Skills { get; set; } public List Battles { get; set; } }