2

I need to design a wrapper around a few database tables, allowing the client to simply execute a GET:

http://myservice/accounts?$filter=name eq alex

And then this service will apply that query against a database table like:

create table account (name varchar, key int)

We would have some controller that would grab that query string and apply it against the dataset, in pseudocode:

public class AccountsController
{
   public HttpResponseMessage Get()
   {
        return _dataSource.Get(Request.ODataQueryString);
    }
}

How do we expose a sql server table to be easily queryable via odata?

1 Answer 1

3

Assuming you're using EntityFramework, you'd just need to register your controller as an OData endpoint, decorate it with the OData [EnableQuery] attribute and return an instance of the class you're targeting via your controller method:

https://learn.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/create-an-odata-v4-endpoint

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.