OData / OData/AspNetCoreOData

$apply is not showing meta data info when I use IActionResult

Open
#181 24 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

I have Get action in controller:

        public IActionResult Get(ODataQueryOptions<TEntity> queryOptions, CancellationToken cancellationToken)
        {
            var query = MyDBContext.Set<Student>().ToList();
            return Ok(query);
        }

When I send this query: Student?$apply=aggregate($count as OrderCount)
It is returning value without meta data.

Actual:

[
    {
        "OrderCount": 3
    }
]

Expected:

{
    "@odata.context": "https://localhost:44383/$metadata#Student(OrderCount)",
    "value": [
        {
            "@odata.id": null,
            "OrderCount": 3
        }
    ]
}

It is working fine when Get looks like:

        public IEnumerable<TEntity> Get(ODataQueryOptions queryOptions, CancellationToken cancellationToken)
        {
            return MyDBContext.Set<TEntity>().ToList();
        }

It is causing problems when entity is Open Type. In open type it looks like:

{
    "$type": "System.Linq.EnumerableQuery`1[[Microsoft.AspNet.OData.Query.Expressions.NoGroupByAggregationWrapper, Microsoft.AspNetCore.OData]], System.Linq.Queryable",
    "$values": [
        {
            "$id": "1",
            "$type": "System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib],[System.Object, System.Private.CoreLib]], System.Private.CoreLib",
            "OrderCount": 3
        }
    ]
}

My project is in .NET 5

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the controller Get action using IActionResult and ODataQueryOptions and compare it with the IEnumerable action that works. Reproduce the Student?$apply=aggregate($count as OrderCount) request, including an open-type entity, and trace how the result is serialized. Done means the response includes the OData context and value metadata rather than a raw array or EnumerableQuery wrapper.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.