I have a problem when I Update the database from model! I have an interface and I identify an Edit Function and I created a class to implement this function as follow:
public void Edit(byte? id)
{
var entity = getByID(id);
UnitOfWork.DbContext.Entry(entity).State = EntityState.Modified;
UnitOfWork.Commit();
}
In the controller I called this function as follow:
[HttpPost]
public ActionResult Edit(BackendModuleViewModel model)
{
var entity = model.ConvertToEntity(model);
_backendModuleRepository.Edit(entity.BNM_ID);
return RedirectToAction("Index");
}
When I run the project it tells me that the primary key is null !
The function (getByID) in Edit that located in a repository is implemented as follow:
public BackendModule getByID(byte? id)
{
var entity = DbSet.FirstOrDefault(x => x.BNM_ID == id);
return entity;
}