'OData in WebAPI without something like Entity Framework

I'm building a WebAPI that is getting its data from legacy systems so no Entity Framework available for me. Now I want to use OData functionality but is not going to work if I have somethink like Entity Framework. But in my research I found out that I can fetch the 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 to an actual SQL query. But this does seem like a lot of work.

My question is, is there another way or a better way to achieve this without using Entity Framework. Any tips/help would be appreciated.



Solution 1:[1]

Either enable query support at startup to allow OData queries for all actions, or decorate your actions with [Queryable]. Then make sure your actions return IQueryable, you can use the .AsQueryable() method on your 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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Troy Carlson