c# - How to select only OData child elements -


i'm building odata application , i'm struggling on how retrieve results , include (child properties).

first, let me show registration in builder:

builder.entityset<aggregatedarticlessearchmodel>("search").entitytype.haskey(x => x.name); 

now, on model i'm returning query:

<entitytype name="aggregatedarticlessearchmodel">     <key>         <propertyref name="name"/>     </key>     <property name="name" nullable="false" type="edm.string"/>     <property name="values" type="collection(zevij_necomij.mobile.app.api.models.occurenceviewmodel)"/> </entitytype> <complextype name="occurenceviewmodel">     <property name="value" type="edm.string"/>     <property name="count" nullable="false" type="edm.double"/>     <property name="articles" type="collection(zevij_necomij.mobile.app.api.models.aggregatedarticledescriptionviewmodel)"/> </complextype> <complextype name="aggregatedarticledescriptionviewmodel">     <property name="name" type="edm.string"/>     <property name="specification" type="edm.string"/>     <property name="brand" type="edm.string"/> </complextype> 

when i'm executing request data, i'm not doing fancy returning results database:

public async task<ihttpactionresult> get() {     // create managers platform context required application.     var classificationmanager = context.createmanager(typeof(aggregatedarticlemanager<>)) aggregatedarticlemanager<iaggregatedarticlestore<aggregatedarticle>>;      var classifications = await classificationmanager.getallasync();      var returnlist = classifications.orderby(x => x.name).select(aggregatedarticlessearchmodel.mapfromdbmodel).tolist();      return ok(returnlist.asqueryable()); } 

since i'm working child objects, list can quite huge:

{   "@odata.context":     "http://api.mobileapp.appserver.dev.dsoft.be/odata/$metadata#search",   "value": [     {       "name": "(veiligheids)slipkoppeling",       "values": [         {           "value": "ja",           "count": 118,       "articles": [         {           "name": "230 v sleuvenzaag",           "specification": "compacte machine",           "brand": "makita"         },         {           "name": "230v cirkelzaag sjs",           "specification": "softstart voor         },     } } 

i can have thousand articles in single set, thus, way return on web api. since don't need properties in single request, thinking let cliënt retrieve child properties using ?$select parameter, cliënts can example:

odata/search?$select=values 

the problem here example, want return count, thus, tought request possible:

odata/search?$select=values/count 

however, leads odata error: "the query specified in uri not valid. found path multiple navigation properties or bad complex property path in select clause. please reword query such each level of select or expand contains either typesegments or properties."

anyone has idea on how solve one?

@complexity

as know, select sub property in property not supported.

however, if build occurenceviewmodel entity type, can use nested $select in $expand meet requirement.

for example:

1) build entity type

builder.entityset<occurenceviewmodel>("viewmodels").entitytype.haskey(x => x.value); 

then, values in aggregatedarticlessearchmodel should navigation property.

2) now, can issue request follows return count property:

get ~/odata/search?$select=values&$expand=values($select=count) 

then, payload should below:

{   "@odata.context":"http://localhost/odata/$metadata#search(values,values(count))","value":[     {       "values":[         {           "count":101.0         },{           "count":102.0         }       ]     },{       "values":[         {           "count":101.0         },{           "count":102.0         }       ]     }   ] } 

hope can you. thanks.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -