diff --git a/Breeze.Sharp/EntityQuery.cs b/Breeze.Sharp/EntityQuery.cs index 2513240..068f4db 100644 --- a/Breeze.Sharp/EntityQuery.cs +++ b/Breeze.Sharp/EntityQuery.cs @@ -217,12 +217,12 @@ public override String GetResourcePath(MetadataStore metadataStore) { /// Return the query as JSON url, e.g. "Customer?{where:{FirstName:'Maria'}}" private string GetJsonResourcePath(string resourceName) { - var json = JsonQueryExpressionVisitor.Translate(this.Expression); + var json = JsonQueryExpressionVisitor.Translate(this.Expression, out string parameters); if (json.Length > 2) { // TODO may be able to get away with not escaping the URI System.Diagnostics.Debug.WriteLine($"json query: {json}"); var uri = Uri.EscapeUriString(json); - return resourceName + '?' + uri; + return resourceName + '?' + uri + (parameters != null ? "&" + parameters : string.Empty); } else { return resourceName; } diff --git a/Breeze.Sharp/Json/JsonQueryExpressionVisitor.cs b/Breeze.Sharp/Json/JsonQueryExpressionVisitor.cs index d0b6531..bf8a97d 100644 --- a/Breeze.Sharp/Json/JsonQueryExpressionVisitor.cs +++ b/Breeze.Sharp/Json/JsonQueryExpressionVisitor.cs @@ -27,7 +27,7 @@ public class JsonQueryExpressionVisitor : ExpressionVisitor { private ListExpressionVisitor expandVisitor; /// Translate the EntityQuery expression into a JSON string - public static string Translate(Expression expression) { + public static string Translate(Expression expression, out string parameters) { var visitor = new JsonQueryExpressionVisitor(); visitor.VisitRoot(expression); @@ -44,7 +44,9 @@ public static string Translate(Expression expression) { //without a server-side custom model binder for 'Customer?{"parameters":{"companyName":"C"}}' I cannot have parameters with right values, //so I have to use this hack if (visitor.Parameters?.Count > 0) - json = json + "&" + string.Join("&", visitor.Parameters.Select(kvp => string.Format("{0}={1}", kvp.Key, kvp.Value))); + parameters = string.Join("&", visitor.Parameters.Select(kvp => string.Format("{0}={1}", kvp.Key, kvp.Value.Replace("&", "%26")))); + else + parameters = null; return json; } diff --git a/Tests/Internal/Tests/JsonQuerySerializationTests.cs b/Tests/Internal/Tests/JsonQuerySerializationTests.cs index f38172c..66570fe 100644 --- a/Tests/Internal/Tests/JsonQuerySerializationTests.cs +++ b/Tests/Internal/Tests/JsonQuerySerializationTests.cs @@ -25,7 +25,7 @@ public void TearDown() { // TODO somehow compare JSON by structure instead of string, so whitespace changes won't matter private void Check(EntityQuery query, string expectedJson) { - var json = JsonQueryExpressionVisitor.Translate(query.Expression); + var json = JsonQueryExpressionVisitor.Translate(query.Expression, out string parameters); Assert.AreEqual(expectedJson, json); }