I have a huge problem with one of our old applications. It is c# with Entity Framework. Now I have a table Person (Name, StreetName, Phone, PostCodeId etc.) and another table PostCode (Id, PostCode, CityName). I have an edit form where the user can add/edit persons. The person edit form includes a combobox for either typing or selecting the postcode.
When the user select/type a new postcode the person object is updated with a new postcode object and when the user saves, the person object is saved. The framework then updates the postcode table, changing the city name of the old postcode to the new city name. What I want it to do is to update the person table with a new postcodeid.
This is the code in the SelectIndexChanged of the postcode combo:
private void PostCodeCombo_SelectedIndexChanged(object sender, EventArgs e)
{
if (PostCodeCombo.SelectedItem != null)
{
person.PostCode = (BSSModel.PostCode)PostCodeCombo.SelectedItem;
personBindingSource.EndEdit();
}
CityNameLabel.Text = person.PostCode.CityName;
}
Can anyone give me some ideas where to look, or what is wrong? I am not that well into how the entity framework works. The Person table has a foreign key to the PostCode table to make the framework link these two in the datamodel. Can this foreign key be wrong somehow?
Best regards Hans Milling...