I have a winforms app with a group of text boxes for an entity, let's call the entity Product
One of my textboxes is hidden because it holds a foreign key to another database object Business Unit
. I populate the hidden textbox using a combobox that looks up values on the parent table. When the selection changes, so does the value in the hidden textbox.
private void businessUnitComboBox_SelectionChangeCommitted(object sender, EventArgs e)
{
this.businessUnitIdTextBox.Text = this.businessUnitComboBox.SelectedValue.ToString();
this.businessUnitComboBox.Focus();
}
Problem is after calling SaveChanges on my context, this change on the hidden textbox is not persisted. Oddly, if I update any of the other Product
textboxes, they save just fine.
The textboxes were added to the project with standard drag and drag drop from Visual Studio's GUI, and a bindingsource was created when adding automatically.
My entities implement INotifyPropertyChanged using fody-propertychanged.
I am struggling to find the issue here. Creating new records works fine, but updating that one Foreign Key value never has.
Is this because it is a navigation property and needs to be handled differently, or are there other possibilities as to why the changes are not persisted? Any help is much appreciated.