OData / OData/AspNetCoreOData

Intercepting after filter

Open
#65 2 comments 0 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've got a collection of users in our database. However, we also have groups that come from an Active Directory source.

We need to collate the filtered users with groups but the function to add groups to each user will need to enumerate the IQueriable so that can add the groups to each user.

This results in the entire user table being loaded into memory > Groups being added to those users before being filtered.

Is there a way that we can intercept/hook the result after the filter has been applied? Then we could add the groups to the filtered subset of users. Is this possible?

Alternatively is there a way that we can get access to the filters, apply them ourselves and then apply the groups?

[EnableQuery(MaxTop = 100, AllowedQueryOptions = Select | Top | Skip | Count | Expand | Filter | OrderBy | Apply)]
[ProducesResponseType(typeof(IQueryable<UserDto>), 200)]
[HttpGet]
[Produces("application/json")]
public IActionResult Get()
{
    var entities = this._profilesService.GetUsers();

    IQueryable<UserDto> projected = _mapper.ProjectTo<UserDto>(entities);
    // this code internally itterates over the users causing them to enumerate before the filter can be applied.
    projected = _profilesService.AddGroupsAndPermissions(projected).AsQueryable();

    return Ok(projected);
}

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 example in the issue and trace how the EnableQuery pipeline applies filters to the returned IQueryable. No source files or tests are named, so first locate the query-application entry point and existing extension hooks. Done would require a defined way to process the filtered subset without eagerly enumerating all users, with coverage for filtering and group enrichment.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.