$apply is not showing meta data info when I use IActionResult
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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