This is my class:
public class tblProdLine : DBModel
{
//==============================================================================
[MaxLength(50)]
public string? Name { get; set; }
//==============================================================================
[ForeignKey("Supervisor")]
public int? SupervisorID { get; set; }
public virtual tblUser? Supervisor { get; set; }
//==============================================================================
}
in my window, Prodline.SupervisorID is binded to a combobox so when user chooses a new Supervisor, its ID will be in SupervisorID:
<select @bind="plineModel.SupervisorID" class="form-control">
<option value="">Choose a user...</option>
@foreach (var user in UserViewModel.Items)
{
<option value="@user.ID">@user.Name</option>
}
</select>
(doesn't support binding the Supervisor itself, it freaks out lol)
but as the Supervisor itself isn’t updated, Entity Framework saves the original Supervisor on “Update”.
I though about modifying the setter of the “SupervisorID” inside the Prodline class to update the “Supervisor”, but is that really the only way?