I am using ASP.NET MVC4 Web API, and my PUT action, I want to do something like this:
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();
}
But the changes in the Foo value
object are not saved. If I were to do each property, it would work, like this:
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();
}
Is there a way that I can updated every property by just assigning the object?