ProVega
ProVega

Reputation: 5914

WebApi OData Metadata / Description

I am using the new 2012.2 OData stuff (Microsoft ASP.NET Web API OData) and following the basic examples. I have a very basic POCO and its being "magically" exposed via my MVC site at /odata:

    ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<Job>("Products");

Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel();
config.Routes.MapODataRoute("ODataRoute", "odata", model);

This seems to magically wire up the odata "service" description file and calls my Products controller which is formatted nicely as ATOM.

My question has to do with the POCO, description and metadata. There is so much magic going on here I don't know where to find the documentation. I would like to be able to:

I don't really know what is generating that "/odata/magic.svc" file, so I don't know how to find documentation on it. Is this WebApi, OData, EntityFramework?

Thanks!

Upvotes: 2

Views: 4153

Answers (1)

RaghuRam Nadiminti
RaghuRam Nadiminti

Reputation: 6793

There is no magic.svc that gets generated. You have done the 3 steps required for building an OData service. Refer to this tutorial and this blog post for details.

When you did,

DataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<Job>("Products");
Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel();

you have built the EDM model for your OData service.

When you did,

config.Routes.MapODataRoute("ODataRoute", "odata", model);

you are telling web API to expose an OData service at ~/odata/ (second argument) using the service model that you have just built.

And when you are trying to fetch the url ~/odata/Products, the OData route that you have added knows that you are trying to access the Products entity set and routes it to the ProductsController. I will try to do a blog post about the conventions that ODataConventionModelBuilder uses and the default OData routing conventions.

And regarding the other two questions,

1) There is no out-of-the-box support for providing atom metadata. But, you can override atom metadata by using the nightly drops that added extensiblity points to the OData formatter. Refer to this answer for details.

2) We don't support aliasing right now. So, no luck there. It is one of the top items in our future plans though.

Upvotes: 4

Related Questions