简体   繁体   中英

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:

  • Provide a "Description" property for my entities (Excel 2013 shows this during the Data Connection Wizard)

  • Override the class name of my POCO with a user friendly name. And as a bonus, allow me to dynamically set this on-the-fly.

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM