Net Core: Using OData in Onion Architecture, Convert Query Parameters Into Linq

It’s been ages since I wrote this function, but the links might help.
GetAll() just returns an IEnumerable.

    [Route(""), HttpGet]
    public IHttpActionResult Get(ODataQueryOptions<Language> queryOptions)
    {
        Log.Info($"{nameof(Get)} (ODataQueryOptions)");

        //OData directly with normal WebAPI
        //https://blogs.msdn.microsoft.com/webdev/2013/02/25/translating-odata-queries-to-hql/
        //https://stackoverflow.com/questions/10781309/asp-net-mvc-4-webapi-manually-handle-odata-queries
        //https://blogs.msdn.microsoft.com/odatateam/2014/07/04/tutorial-sample-using-odatauriparser-for-odata-v4/

        //OData without entity framework, but full-on odata controller
        //http://www.odata.org/blog/how-to-use-web-api-odata-to-build-an-odata-v4-service-without-entity-framework/

        //OData tips and tricks
        //https://blogs.msdn.microsoft.com/davidhardin/2014/12/17/web-api-odata-v4-lessons-learned/

        return Ok(queryOptions.ApplyTo(_repository.GetAll().AsQueryable()));
    }

Leave a Comment