Skip to content

Best Place to Calculate Expensive Operations for Query Scoped Results #539

Answered by dweeden
dweeden asked this question in Q&A
Discussion options

You must be logged in to vote

Figured it out using this post as a starting point

For my scenario, simply applying the query options worked best as per below. Note that EntityToModel is a custom conversion function that returns a TModel from a TEntity.

It was annoying the ApplyTo wouldn't work with my TEntity class which differed from the public TModel so I used a dictionary map as a bridge to overcome that issue.

Hope this helps someone else :)

[HttpGet("/odata/[controller]")]
public IActionResult Get(ODataQueryOptions<TModel> options, bool editMode)
{
    // validate options
    options.Validate(new ODataValidationSettings());

    // build entity map  
    var entityMap = Entities.Where(e => editMode || !e.IsDeleted &&

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dweeden
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant