OData / OData/AspNetCoreOData

How to defer creation of ODataQueryOptions to repository layer

Open
#862 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

followup
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Using OData directly on a model in the controller and returning a IQueryable is not an option for many reasons (i.e. access control, no one-to-one fields of DTO to DB, clean architecture, etc). The common option that I found is to have a parameter of type ODataQueryOptions in the controller method and then use the ApplyTo method later.

If you use Clean Architecture a query request in application layer is called that will call the repository. The ApplyTo method will then be called in the repository. This requires that the ODataQueryOptions type needs to be pushed down through all layers and all layers depend on OData.

A better solution would be to just save the OData query that is used in the REST call as a primitive string type and pass it through to the repository. Therfore neither API nor application layers need to depend on OData.

Right now the magic of parsing the query string and creating the ODataQueryOptions type happens in the middleware before the controller. Is it possible to call the parser directly so I can use the query string as a paramater and create the ODataQueryOptions type in the repository?

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 by tracing how the middleware parses the REST query string and creates ODataQueryOptions before the controller. Determine whether that parser can be called directly with a primitive query string so repository-layer creation avoids OData dependencies in the API and application layers. Done means a supported approach or a clear explanation of its limitations.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.