So what is the suggested way of extending OU? I would like to add a extra property, such as OUType int or similar.
I have had a similar issue, it is caused because the Navigation properties lose state when POSTed to the update, so AutoMapper then thinks you have updated the entity to a null value.
It is a symptom of trying to use AutoMapper to map the DTO back to the entity.
Check you need the navigation properties, or just the id's, or code the mapping manually, or, define a second DTO without navigation properties, then in the update map the original DTO to the cutdown DTO, then map that DTO to the domain entity (not very pretty, but effective).
like this...
if (ModelState.IsValid)
{
var entity = await _entityManager.FindAsync(model.entityDto.Id);
//map via edit DTO to ignore Navigation Properties
var editEntityDto = model.entityDto.MapTo<EntityEditDto>();
editEntityDto.MapTo(activity);
await _activityManager.UpdateAsync(entity);
return RedirectToAction("Index");
}
hope that makes sense!