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:

  1. update child:

    patch/put: ~/child1s(...)

  2. update parent

    patch/put: ~/entity1s(...)

  3. update relateship between parent , child:

    patch/put ~/entity1s(...)/childrenlist/$ref

with entity reference links content.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -