OData / OData/AspNetCoreOData

Modify OData API response after OData is executed

Open
#614 5 comments 0 reactions 2 assignees View on GitHub

@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

  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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.