Odata中的关系数据支持web api [英] Relational data in Odata supported web api

查看:91
本文介绍了Odata中的关系数据支持web api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我目前正在研究(基本上是研究)OData。所以我是开放数据协议的新手。



我想在我的web api项目中使用这个工具。根据我要求获取关系数据的要求。基本上来自父表和子表的数据。



一切似乎都运转正常。但是当我获取这个关系数据时,它只给出了父表中的数据,而不是来自子表。 (可能是因为自我引用。)



有没有人知道如何解决这个问题?



如果我创建一个ViewModel并将数据输入到那里,那么它会给我406:不可接受。

Hi,

I am currently working on (basically researching) on OData. So I am new to open data protocol.

And i want to use this facility with my web api project. As per the requirement i want to fetch the relational data. Basically a data from Parent and Child tables.

Everything seems to be working fine. But as i fetch this relational data it gives me only data from the parent table and not from the child table. (May be because of self referencing. )

Does any one has any idea about how to resolve this issue ?

And if i create a ViewModel and feed data into that than it gives me 406: not acceptable.

推荐答案

您需要配置一条到你的路线odata终点。这是在Register方法的App_Start\WebApiConfig.cs文件中完成的。使用以下代码添加实体模型和路径:

You would need to configure a route to your odata endpoint. This is done inside the App_Start\WebApiConfig.cs file in the Register method. Use the following code to add an entity model and a route:
ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<product>("ProductSet");

Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel();
config.Routes.MapODataRoute("ODataRoute", "odataSuffix", model);
</product>





请注意,控制器的名称应与EntitySet的名称相匹配。在此示例中,实体集的名称为ProductSet,因此您的控制器必须被称为ProductSetController。



配置完成后,可以通过以下URL访问产品模型:



Note that the name of your controller should match the name of EntitySet. In this example the name of entity set is ProductSet so your controller must be called ProductSetController.

Once this is configured the Product model can be accessed by the following url:

http://hostname:portNumber/odataSuffix/ProductSet


这篇关于Odata中的关系数据支持web api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆