This repository has been archived by the owner on Dec 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Trevor Pilley edited this page Apr 7, 2017
·
55 revisions
Welcome to the Net.Http.WebApi.OData wiki!
Net.Http.WebApi.OData is a C# library which parses an OData query uri into an object model which can be used to query custom data sources which are not IQueryable
.
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Configure routes, etc
// Build the OData Entity Data Model
var entityDataModelBuilder = new EntityDataModelBuilder();
entityDataModelBuilder.RegisterEntitySet<Category>("Categories");
entityDataModelBuilder.RegisterEntitySet<Product>("Products");
entityDataModelBuilder.BuildModel();
}
}
To use it in your own Web API, firstly install the nuget package Install-Package Net.Http.WebApi.OData
and then in your controller, define a Get method which accepts a single parameter of ODataQueryOptions
:
public IEnumerable<MyClass> Get(ODataQueryOptions queryOptions)
{
// Implement query logic.
}