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 bound to a combobox, so when the user chooses a new supervisor, its ID will be stored 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>But as the supervisor itself isn't updated, Entity Framework saves the original Supervisor on "Update".
I thought about modifying the setter of SupervisorID in the Prodline class to update the Supervisor, but is that really the only way?
Edit:my "Put" code:
private readonly HttpClient _httpClient;public DbApiClientService(ApiClientOptions apiClientOptions){ _httpClient = new HttpClient(); _httpClient.BaseAddress = new Uri(apiClientOptions.ApiBaseAddress);}public async Task UpdateItem<T>(T item, int Id){ string endpoint = GetEndpointName<T>(); var response = await _httpClient.PutAsJsonAsync($"/api/{endpoint}/{Id}", item); var responseContent = await response.Content.ReadAsStringAsync();private string GetEndpointName<T>(){ return typeof(T).Name;}