-
Notifications
You must be signed in to change notification settings - Fork 0
Home
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
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");
.
Next, you are ready to start adding OData aware controllers.