For some reason my edit action are not updating my navigations properties Check de codes
public ActionResult Edit(ClienteViewModel clienteViewModel)
{
if (ModelState.IsValid)
{
var cliente = Mapper.Map<Clientes>(clienteViewModel);
_context.Entry(cliente).State = EntityState.Modified;
_unitOfWork.Commit();
return RedirectToAction("Index");
}
return View(clienteViewModel);
}
Any ideas?
EDIT I added a hidden field with endereco.id on edit view and now Endereco.Id is going to controller, but the error still the same


If you look at the primary key
Idof your navigational propertyEnderecoyou will see that its value isGuid.Empty00000000-0000-0000-0000-000000000000.So updating that entity will generate a SQL query with this
WHEREclause below:Of course a line with that empty guid doesn't exist into your table.
Your original code do a mapping with AutoMapper so make sure that all properties are mapped correctly when calling the line below:
Updates: Based on your comment you also need to be sure that the navigational property state is changed to
EntityState.Modified(because changing the root entity's state doesn't impact the navigational properties) like below: