odata - How can I update entity with its children? Patch method doesn't work -
i must update entity children list shown here:
 public class entity1   {      int id{get;set;}      observablecollection<child1> childrenlist {get;set;}      string name{get;set;}  }  public class child1 {     string nome{get;set;}     string cognome {get;set;} }   i implemented patch method in way:
[acceptverbs("patch", "merge")] public async task<ihttpactionresult> patch([fromodatauri] int key, delta<entity1> entitydelta) {              if (!modelstate.isvalid)             {                 return badrequest(modelstate);             }             var entity = await context.entity1.findasync(key);             if (entity == null)             {                 return notfound();             }             entitydelta.patch(entity);              try             {                 await context.savechangesasync();             }             catch (dbupdateconcurrencyexception)             {                 return notfound();             }             return updated(entity); }   but when try call fiddler in way:
url: http://localhost/odata4/entity1(1)/  patch request  request headers: content-type: application/json  request body:  { name: "pippo2", childrenlist:[{ nome: "test", cognome: "pippo" }] }   it gives error in model.isvalid property , specified return error:
cannot apply patch navigation property 'childrenlist' on entity type 'entity1'.
how can solve it? patch method correct method use?
odata v4 spec says update entity:
the entity must not contain related entities inline content. may contain binding information navigation properties. single-valued navigation properties replaces relationship. collection-valued navigation properties adds relationship.
so, can use:
update child:
patch/put: ~/child1s(...)
update parent
patch/put: ~/entity1s(...)
update relateship between parent , child:
patch/put ~/entity1s(...)/childrenlist/$ref
with entity reference links content.
Comments
Post a Comment