Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Adds LINQ support for JsonObject #4856

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -949,6 +951,22 @@ public async Task LinqSelectEverythingWithoutQueryableTest()
Assert.AreEqual(2, (await this.FetchResults<ToDoActivity>(queryDefinition)).Count);
}

[TestMethod]
public async Task LinqJsonObjectTest()
{
await ToDoActivity.CreateRandomItems(this.Container, pkCount: 2, perPKItemCount: 1, randomPartitionKey: true);

IOrderedQueryable<JObject> queryableJObject = this.Container.GetItemLinqQueryable<JObject>();
IQueryable<JObject> queryJObject = queryableJObject.Where(f => (string)f["id"] == "fooBar");
string queryTextJObject = queryJObject.ToString();

IOrderedQueryable<JsonObject> queryableJsonObject = this.Container.GetItemLinqQueryable<JsonObject>();
IQueryable<JsonObject> queryJsonObject = queryableJsonObject.Where(f => (string)f["id"] == "fooBar");
string queryTextJsonObject = queryJsonObject.ToString();

Assert.AreEqual(queryTextJObject, queryTextJsonObject);
}

private class NumberLinqItem
{
public string id;
Expand Down