J'utilise ASP.NET MVC4 Web API, et mon action PUT, je veux faire quelque chose comme ça :
public void Put(string id, [FromBody]Foo value)
{
var context = new FooBarEntities();
Foo existingFoo = context.Foos.Where(x => x.Id == id).First();
existingFoo = value;
context.SaveChanges();
}
Mais les changements dans la Foo value
ne sont pas sauvegardés. Si je devais faire chaque propriété, cela fonctionnerait comme suit :
public void Put(string id, [FromBody]Foo value)
{
var context = new FooBarEntities();
Foo existingFoo = context.Foos.Where(x => x.Id == id).First();
existingFoo.Prop1 = value.Prop1;
existingFoo.Prop2 = value.Prop2;
context.SaveChanges();
}
Existe-t-il un moyen de mettre à jour chaque propriété en assignant simplement l'objet ?