I have a .NET Core API which is supposed to update an entity in the database using Entity Framework Core.
When a user edits an existing entry, the edit form only sends back the edited data, not the full entity.
Let's say we have a shop:
public class Shop {
public int ShopID { get;set;}
public string Name { get;set;}
public string Address { get;set;}
}
Now, the user edits the address and saves it. Data sent back to the API will be the ShopID and the Address. However, using the model binding below would set the Name to NULL, which is logical since it hasn't actually been passed in.
[Route("~/shop/[action]")]
public IActionResult Update([FromBody] Shop shop)
{
_context.Shops.Update(shop);
_context.SaveChanges();
return new JsonResult(new { result = true });
}
So, since I don't know which property/ies might be updated (in practice, there's a lot more properties), I need some way of dynamically updating only the fields sent through in the POST request.
Thanks in advance.