Missing inverse property in asp.net webapi odata $metadata -
have simple relationship between 2 entities , trying expose them asp.net webapi odata controllers seems wrong $metadata.
when run jaydatasvcutil.exe on $metadata warning: inverseproperty other side missing.
when use breezejs loadnavigationproperty similar error.
i have problem official example. http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/working-with-entity-relations
you can observe $metadata here http://sdrv.ms/z5klfw
please help.
when generating navigation properties don't reuse relationships.
for example, lets 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 navigation properties generate looks 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" />
notice generating 2 relationships instead of one. reason is hard problem figure out if 2 navigation properties represent same relationship. take instance of product , 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; } }
it not trivial figure out maufacturer.rawmaterials , product.consumers should share same relationship , manufaturer.produces , product.producers should share same relationship. chose not because clients know of don't make out of information.
all happens because odata uses same edm model entityframework. entityframework requires information maps these relationships association sets become tables in database.
another reason chose not going away in odata v4. check out working draft here (page 23 , page 57 of interest). in short, navigation properties in $metadata in odata v4 more this,
<navigationproperty name="category" type="self.category" nullable="false" partner="products" />
notice there no relationship , there no association sets.
Comments
Post a Comment