简体   繁体   English

WebApi OData元数据/说明

[英]WebApi OData Metadata / Description

I am using the new 2012.2 OData stuff (Microsoft ASP.NET Web API OData) and following the basic examples. 我正在使用新的2012.2 OData东西(Microsoft ASP.NET Web API OData)并遵循基本示例。 I have a very basic POCO and its being "magically" exposed via my MVC site at /odata: 我有一个非常基本的POCO,通过我的MVC网站/ 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. 这似乎神奇地连接了odata“服务”描述文件,并调用了我的Products控制器,该控制器的格式很好,为ATOM。

My question has to do with the POCO, description and metadata. 我的问题与POCO,描述和元数据有关。 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) 为我的实体提供“描述”属性(Excel 2013在“数据连接向导”中显示了此属性)

  • Override the class name of my POCO with a user friendly name. 用用户友好的名称覆盖我的POCO的类名称。 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. 我真的不知道是什么生成了“ /odata/magic.svc”文件,所以我不知道如何找到该文件。 Is this WebApi, OData, EntityFramework? 这是WebApi,OData,EntityFramework吗?

Thanks! 谢谢!

There is no magic.svc that gets generated. 没有生成的magic.svc。 You have done the 3 steps required for building an OData service. 您已完成构建OData服务所需的3个步骤。 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. 您已经为OData服务构建了EDM模型

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. 您告诉Web API使用您刚刚构建的服务模型在〜/ odata /(第二个参数)处公开OData服务。

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. 并且,当您尝试获取url〜/ odata / Products时,添加的OData路由知道您正在尝试访问Products实体集并将其路由到ProductsController。 I will try to do a blog post about the conventions that ODataConventionModelBuilder uses and the default OData routing conventions. 我将尝试撰写有关ODataConventionModelBuilder使用的约定和默认OData路由约定的博客文章。

And regarding the other two questions, 关于其他两个问题,

1) There is no out-of-the-box support for providing atom metadata. 1)没有提供原子元数据的现成支持。 But, you can override atom metadata by using the nightly drops that added extensiblity points to the OData formatter. 但是,您可以通过使用向OData格式化程序添加可扩展性点的夜间删除来覆盖原子元数据。 Refer to this answer for details. 有关详细信息,请参阅此答案

2) We don't support aliasing right now. 2)我们目前不支持别名。 So, no luck there. 所以,那里没有运气。 It is one of the top items in our future plans though. 不过,这是我们未来计划中的头号项目之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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