Thursday 15 August 2013

asp.net web api - Navigation property values not added to entity -



asp.net web api - Navigation property values not added to entity -

i've webapi odata v3 (5.6.3) service (without ef) phone call breeze using server side metadata. unfortunately cannot navigation properties load correctly in breeze.

the model defined following:

public class parentitem { private readonly list<childitem> childitems = new list<childitem>(); [key] public int id { get; set; } public virtual icollection<childitem> childitems { { homecoming this.childitems; } } #endregion } public class childitem { [key] public int id { get; set; } [foreignkey("parentitem")] public int? parentitemid { get; set; } public virtual parentitem parentitem { get; set; } }

these metadata generated server:

<?xml version="1.0" encoding="utf-8"?> <edmx:edmx version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"> <edmx:dataservices m:dataserviceversion="3.0" m:maxdataserviceversion="3.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <schema namespace="solutions2share.solutions.meetingmanagerweb.models" xmlns="http://schemas.microsoft.com/ado/2009/11/edm"> <entitytype name="parentitem"> <key> <propertyref name="id" /> </key> <property name="id" type="edm.int32" nullable="false" /> <navigationproperty name="childitems" relationship="mynamespace_childitem_childitemspartner" torole="childitems" fromrole="childitemspartner" /> </entitytype> <entitytype name="childitem"> <key> <propertyref name="id" /> </key> <property name="id" type="edm.int32" nullable="false" /> <property name="parentid" type="edm.int32" /> <navigationproperty name="parentitem" relationship="mynamespace_parentitem_parentitempartner" torole="parentitem" fromrole="parentitempartner" /> </entitytype> <association name="mynamespace_childitem_childitemspartner"> <end type="mynamespace.childitem" role="childitems" multiplicity="*" /> <end type="mynamespace.parentitem" role="childitemspartner" multiplicity="0..1" /> </association> <association name="mynamespace_parentitem_parentitempartner"> <end type="mynamespace.parentitem" role="parentitem" multiplicity="0..1" /> <end type="mynamespace.childitem" role="parentitempartner" multiplicity="0..1" /> </association> <entitycontainer name="container" m:isdefaultentitycontainer="true"> <entityset name="parentitems" entitytype="mynamespace.parentitem" /> <entityset name="childitems" entitytype="mynamespace.childitem" /> <associationset name="mynamespace_childitem_childitemspartnerset" association="mynamespace_childitem_childitemspartner"> <end role="childitemspartner" entityset="parentitems" /> <end role="childitems" entityset="childitems" /> </associationset> <associationset name="mynamespace_parentitem_parentitempartnerset" association="mynamespace_parentitem_parentitempartner"> <end role="parentitempartner" entityset="childitems" /> <end role="parentitem" entityset="childitems" /> </associationset> </entitycontainer> </schema> </edmx:dataservices> </edmx:edmx>

i'm using webapiodata on client:

breeze.config.initializeadapterinstance('dataservice', 'webapiodata', true);

the query i'm execute looks this:

breeze.entityquery().from('parentitems').expand('childitems');

the server phone call returns right items:

{ "odata.metadata":"http://example.com/api/$metadata#parentitems","value":[ { "odata.type":"mynamespace.parentitem","odata.id":"http://example.com/api/parentitems(1)","childitems@odata.navigationlinkurl":"http://example.com/api/parentitems(1)/childitems","childitems":[ { "odata.type":"mynamespace.childitem","odata.id":"http://example.com/api/childitems(1)","parentitem@odata.navigationlinkurl":"http://example.com/api/childitems(1)/parentitem","id":1,"parentitemid":1 },{ "odata.type":"mynamespace.childitem","odata.id":"http://example.com/api/childitems(2)","parentitem@odata.navigationlinkurl":"http://example.com/api/childitems(2)/parentitem","id":2,"parentitemid":1 } ],"id":1 } ] }

but childitems property of parentitem entity empty.

edit: if phone call manager.getentities()after executing query parent , kid items returned.

asp.net-web-api odata breeze

No comments:

Post a Comment