Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.
Trevor Pilley edited this page Mar 5, 2018 · 6 revisions

NuGet version

Getting Started

In order to use the OData extension for the MicroLite ORM framework, you need to reference it in your solution. The easiest way to do this is install it via NuGet (if you are unfamiliar with NuGet, it's a package manager for Visual Studio - visit nuget.org for more information).

Install-Package MicroLite.Extensions.WebApi.OData

Configuration

The OData extension extends the MicroLite WebApi extension, see Configuring the WebApi Extension first.

You then need to configure the entity model (the types which your OData controllers will use):

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");, if you use http://myservice/odata/Product then register the Entity Set using .RegisterEntitySet<Product>("Product");.

Controllers

Next, you are ready to start adding OData aware controllers.

Clone this wiki locally