OData in WebAPI without something like Entity Framework

I am creating a WebAPI that retrieves its data from legacy systems, so there is no Entity Framework for me. Now I want to use OData functionality, but I won’t work if I have something like Entity Framework. But in my research, I found out that I can get ODataQueryOptions like this.

public IQueryable<Vehicle> Get(ODataQueryOptions opts) { var dal = new DataAccessVehicles(); return (dal.GetVehicles(opts)); } 

In my DAL, I could translate the OData query into a real SQL query. But that seems like a lot of work.

My question is is there any other way or better way to achieve this without using the Entity Framework. Any advice / help would be appreciated.

+7
source share
1 answer

Turn on query support at startup to allow OData queries for all actions or to enrich your actions with [Queryable] . Then make sure your actions are returned IQueryable , you can use the .AsQueryable() method for existing collections.

Example:

 [Queryable] public IQueryable<Product> Get() { return products.AsQueryable(); } 

Take a look at this article:

http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options

0
source

Source: https://habr.com/ru/post/972831/


All Articles