Skip to content

DwaynesWorld/Net.Http.WebApi.OData

 
 

Repository files navigation

Net.Http.WebApi.OData

NuGet version Build Status

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. It was extracted from the MicroLite.Extensions.WebApi library into a separate project so that it could be easily used by others.

Installation

To use it in your own Web API you need to install the nuget package Install-Package Net.Http.WebApi.OData

Configuration

Somewhere in your application startup/webapi configuration, specify the types which will be used for OData queries:

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        // Wire-up OData and define the Entity Data Model
        config.UseOData(entityDataModelBuilder =>
        {
            entityDataModelBuilder.RegisterEntitySet<Category>("Categories", x => x.Name);
            entityDataModelBuilder.RegisterEntitySet<Employee>("Employees", x => x.EmailAddress);
            entityDataModelBuilder.RegisterEntitySet<Order>("Orders", x => x.OrderId);
            entityDataModelBuilder.RegisterEntitySet<Product>("Products", x => x.Name);
        });

        // Use Attribute Mapping for the OData controllers
        config.MapHttpAttributeRoutes();
    }
}

Note that when you register an Entity Set, you also specify the name of the Entity Set. The name needs to match the URL you intend to use so if you use http://myservice/odata/Products then register the Entity Set using .RegisterEntitySet<Product>("Products", x => x.Name);, if you use http://myservice/odata/Product then register the Entity Set using .RegisterEntitySet<Product>("Product", x => x.Name);.

Usage

In your controller(s), define a Get method which accepts a single parameter of ODataQueryOptions:

public IEnumerable<Category> Get(ODataQueryOptions queryOptions)
{
    // Implement query logic.
}

Supported OData Versions

The library supports OData 4.0

Supported .NET Framework Versions

The NuGet Package contains binaries compiled against:

  • .NET 4.5 and Microsoft.AspNet.WebApi.Core 5.2.7

To find out more, head over to the Wiki.

About

A C# library for parsing OData queries

Resources

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE
Unknown
License.txt

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 98.5%
  • Smalltalk 1.5%