Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

A .NET 4.5 library which uses Net.Http.OData with an implementation for ASP.NET WebApi.

License

Notifications You must be signed in to change notification settings

Net-Http-OData/Net.Http.WebApi.OData

Repository files navigation

Net.Http.WebApi.OData

Net.Http.WebApi.OData is a .NET 4.5 library which uses Net.Http.OData with an implementation for ASP.NET WebApi.

Nuget

Branch Status
/develop GitHub last commit (branch) Build Status Nuget (with prereleases)
/master GitHub last commit Build Status Nuget GitHub Release Date

Installation

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)
                .RegisterEntitySet<Employee>("Employees", x => x.EmailAddress)
                .RegisterEntitySet<Order>("Orders", x => x.OrderId)
                .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:

[RoutePrefix("odata")]
public class ProductsController : ODataController
{
    [HttpGet]
    [Route("Products")]
    public IHttpActionResult Get(ODataQueryOptions queryOptions)
    {
        // Implement query logic.
        var results = ...

        var responseContent = new ODataResponseContent { Value = results };

        if (queryOptions.Count)
        {
            responseContent.Count = results.TotalCount;
        }

        return Ok(responseContent);
    }
}

Supported OData Versions

The library supports OData 4.0 query syntax, for a full list of supported features see Supported Query Syntax in the Net.Http.OData Wiki.

Supported .NET Versions

The NuGet Package contains binaries compiled against:

  • .NET Framework 4.5
    • Microsoft.AspNet.WebApi.Core 5.2.7
    • Net.Http.OData 5.0.0

To find out more, head over to the Wiki.

About

A .NET 4.5 library which uses Net.Http.OData with an implementation for ASP.NET WebApi.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages