user265312
user265312

Reputation: 75

DocumentDB .Net Client Library LINQ Aggregates Error

I'm just getting started with DocumentDB and wanted to try out the aggregation features recently added. However, when I try to use them I get the following exception: Query expression is invalid, expression return type System.Int32 is unsupported. Query must evaluate to IEnumerable.

I've already got a DocumentClient object, named client below.

var collectionUri = UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId);
var options = new FeedOptions {MaxItemCount = -1, EnableCrossPartitionQuery = true};

var count = client.CreateDocumentQuery<LogEvent>(collectionUri, options)
    .Where(f => f.Player == "SomePlayer")
    .Count();

I'm working against the local emulator. The collection has four documents in it.

Is this something that's just not available in the local emulator right now? Or am I doing something incorrectly?

Upvotes: 1

Views: 80

Answers (1)

Bruce Chen
Bruce Chen

Reputation: 18465

According to your code, I tested it against my Azure DocumentDB (instead of the local emulator), then I could encounter the same error as you provided:

enter image description here

As Aravind Ramachandran mentioned about the version, then I checked my installed version and found it was Microsoft.Azure.DocumentDB 1.11.4. After updating the version to 1.12.1 or the higher version, then I could retrieve the expected result.

Here is the release notes of Azure DocumentDB for .NET as follows:

Changes in 1.12.1

Added LINQ support for aggregation queries (COUNT, MIN, MAX, SUM, and AVG).

Upvotes: 1

Related Questions