Modify OData API response after OData is executed
Open
@ElizabethOkerio is already working on this.
Since Jun 7, 2022.
question
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
How do I modify the result data of an OData API?
For example, in the response of a list OData API, we want to set some property to null.
I tried to do it in IResultFilter.OnResultExecuted like this:
public class MyResultFilter : Attribute, IResultFilter
{
public void OnResultExecuted(ResultExecutedContext context)
{
var result = context.Result as OkObjectResult;
var data = result.Value as EntityQueryable<Microsoft.AspNetCore.OData.Query.Wrapper.SelectAllAndExpand<DbContext.Table1>>;
//modify data
}
}
[EnableQuery]
[MyResultFilter]
public IActionResult Get()
{
var querable = DbContext.Table1.AsQueryable<Table1>();
return Ok(querable);
}
But the SelectAllAndExpand is internal so the code won't compile.
Is there a better way to do this?
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.
Assessment
This issue has not been assessed yet.