René Sackers
René Sackers

Reputation: 2635

Azure Cosmos with .NET SDK 3.6 throws Group By is not supported on LINQ query

According to the documentation group by is supported since the .NET SDK 3.3 I've written some testing code in LINQPad to query my local Azure Cosmos Emulator using LINQ, but it's throwing the following error message:

Method 'GroupBy' is not supported., Windows/10.0.18362 cosmos-netstandard-sdk/3.4.2

I'm using the NuGet package Microsoft.Azure.Cosmos version 3.6.0.

My query looks like this:

var query = container.GetItemLinqQueryable<MyObject>()
    .GroupBy(a => a.Id)
    .ToFeedIterator();

(Please note, I realize the query is non-sensical, it's just by example)

Executing similar SQL in the web interface works just fine:

SELECT
    o.id
FROM
    MyObjects o
GROUP BY
    o.id

If I execute SQL through the C# SDK, that also seems to work fine:

var queryDef = new QueryDefinition("SELECT i.id FROM items i GROUP BY i.id");
var query = container.GetItemQueryIterator<ToDoItem>(queryDef);
var items = new List<ToDoItem>();

while (query.HasMoreResults)
{
    items.AddRange(await query.ReadNextAsync());
}

items.Dump();

Upvotes: 3

Views: 2964

Answers (1)

Matias Quaranta
Matias Quaranta

Reputation: 15583

The linked document describes the GROUP BY support on the SQL Query engine, that is why running a query with GROUP BY on the Portal or in the SDK as text works.

LINQ support is separate and currently not there for GroupBy (it does not translate to the SQL Query text).

I have added an Issue on GitHub that will be used to track progress on it.

Upvotes: 4

Related Questions