缺少反向属性在asp.net中的WebAPI ODATA $元 [英] Missing inverse property in asp.net webapi odata $metadata

查看:163
本文介绍了缺少反向属性在asp.net中的WebAPI ODATA $元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个实体之间的非常简单的关系,我想用asp.net的WebAPI ODATA控制器揭露他们,但似乎,什么是错用$元数据。

have very simple relationship between two entities and I am trying to expose them with asp.net webapi odata controllers but it seems that something is wrong with $metadata.

当我在$运行的元数据我jaydatasvcutil.exe得到警告:inverseProperty对方缺少

When I run jaydatasvcutil.exe on the $metadata I get warning: inverseProperty other side missing.

当我使用breezejs loadNavigationProperty我得到类似的错误。

When I use breezejs loadNavigationProperty I get similar error.

我甚至官方例子的问题。
<一href=\"http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/working-with-entity-relations\" rel=\"nofollow\">http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/working-with-entity-relations

I have the problem even with official example. http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/working-with-entity-relations

您可以在这里观察$元 http://sdrv.ms/Z5Klfw

You can observe the $metadata here http://sdrv.ms/Z5Klfw

请帮忙。

推荐答案

当我们正在生成导航属性,我们不重用的关系。

When we are generating navigation properties we don't reuse the relationships.

举例来说,假设你有简单的模型,

For example, lets say you have simple model,

public class Product
{
    public int Id { get; set; }
    public Supplier Supplier { get; set; }
}
public class Supplier
{
    public int Id { get; set; }
    public Product[] Products { get; set; }
}

对于我们生成看起来像这样的导航属性的元数据$

The $metadata for the navigation properties that we generate looks like this,

<NavigationProperty Name="Supplier" Relationship="ProductsService.Models.ProductsService_Models_Product_Supplier_ProductsService_Models_Supplier_SupplierPartner" ToRole="Supplier" FromRole="SupplierPartner" />

<NavigationProperty Name="Products" Relationship="ProductsService.Models.ProductsService_Models_Supplier_Products_ProductsService_Models_Product_ProductsPartner" ToRole="Products" FromRole="ProductsPartner" />

请注意,我们正在生成两个关系,而不是一个。我们这样做的原因是,它是要弄清楚如果两个导​​航属性​​重新present同一关系的难题。以产品和制造商的实例。

Notice that we are generating two relationships instead of one. The reason we do that is that it is a hard problem to figure out if two navigation properties represent the same relationship. Take the instance of Product and Manufacturer.

public class Manufacturer
{
    public int Id { get; set; }
    public Product[] RawMaterials { get; set; }
    public Product[] Produces { get; set; }
}
public class Product
{
    public int Id { get; set; }
    public Manufacturer[] Producers { get; set; }
    public Manufacturer[] Consumers { get; set; }
}

这是不平凡的弄清楚,Maufacturer.RawMaterials和Product.Consumers应该共享同样的关系,并Manufaturer.Produces和Product.Producers应该共享同样的关系。我们没有选择这样做,因为我们知道客户没有太大的出这个信息。

It is not trivial to figure out that Maufacturer.RawMaterials and Product.Consumers should share the same relationship and Manufaturer.Produces and Product.Producers should share the same relationship. We chose not to do it because the clients that we know of don't make much out of this information.

这一切是因为OData的使用相同的EDM模型作为的EntityFramework。的EntityFramework需要此信息,因为它映射这些关系协会集这将成为数据库中的表。

All this happens because OData uses the same EDM model as the entityframework. Entityframework requires this information as it maps these relationships to association sets which would become tables in the database.

我们选择不这样做的另一个原因是,这可能在OData的V4将消失。退房的工作草案<一个href=\"https://www.oasis-open.org/committees/download.php/48587/odata-core-v4.0-wd01-part3-csdl-2013-03-19.doc\">here (第23页和57页的将是利息)。总之,在$元数据导航性质的OData V4看起来会像这样,

Another reason we chose not to do it is that this could be going away in OData V4. Check out the working draft here (page 23 and page 57 would be of interest). In short, navigation properties in $metadata in OData V4 would look more like this,

<NavigationProperty Name="Category" Type="Self.Category" Nullable="false" Partner="Products" />

请注意,没有关系,就没有关联集。

Notice that there is no relationship and there would be no association sets.

这篇关于缺少反向属性在asp.net中的WebAPI ODATA $元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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