From 6ef98430fb93316bb8a79f010c4e8b07a0490de6 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Fri, 25 Oct 2024 20:08:03 -0700 Subject: [PATCH] initial commit --- .../BuiltinFunctions/BuiltinFunctionVisitor.cs | 3 +-- .../CosmosItemLinqTests.cs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/BuiltinFunctionVisitor.cs b/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/BuiltinFunctionVisitor.cs index 82f427c206..224e0f5e1a 100644 --- a/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/BuiltinFunctionVisitor.cs +++ b/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/BuiltinFunctionVisitor.cs @@ -5,7 +5,6 @@ namespace Microsoft.Azure.Cosmos.Linq { using System; - using System.Collections.Generic; using System.Globalization; using System.Linq.Expressions; using Microsoft.Azure.Cosmos; @@ -97,7 +96,7 @@ public static SqlScalarExpression VisitBuiltinFunctionCall(MethodCallExpression } // Array functions - if (declaringType.IsEnumerable()) + if (declaringType.IsEnumerable() || declaringType == typeof(System.Text.Json.Nodes.JsonNode)) { return ArrayBuiltinFunctions.Visit(methodCallExpression, context); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemLinqTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemLinqTests.cs index efffeae1cb..31017451f8 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemLinqTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemLinqTests.cs @@ -8,12 +8,14 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests using Microsoft.Azure.Cosmos.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; + using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Linq.Dynamic; using System.Linq.Expressions; + using System.Text.Json.Nodes; using System.Threading.Tasks; [TestClass] @@ -949,6 +951,22 @@ public async Task LinqSelectEverythingWithoutQueryableTest() Assert.AreEqual(2, (await this.FetchResults(queryDefinition)).Count); } + [TestMethod] + public async Task LinqJsonObjectTest() + { + await ToDoActivity.CreateRandomItems(this.Container, pkCount: 2, perPKItemCount: 1, randomPartitionKey: true); + + IOrderedQueryable queryableJObject = this.Container.GetItemLinqQueryable(); + IQueryable queryJObject = queryableJObject.Where(f => (string)f["id"] == "fooBar"); + string queryTextJObject = queryJObject.ToString(); + + IOrderedQueryable queryableJsonObject = this.Container.GetItemLinqQueryable(); + IQueryable queryJsonObject = queryableJsonObject.Where(f => (string)f["id"] == "fooBar"); + string queryTextJsonObject = queryJsonObject.ToString(); + + Assert.AreEqual(queryTextJObject, queryTextJsonObject); + } + private class NumberLinqItem { public string id;