I am writing a C#.Net windows application using EF for communicating with SQL Express. I have a Contacts table in my application. For editing a Contact I have called a new windows form by ShowDialogue() method and used ApplyCurrentValue method. In this form if I get the list of my contacts (using db.Contacts.ToList() method), the changes could be seen but when I close the form and want to refresh the gridview which exist in the main form, I cannot see the changes unless I restart the whole application.
here is the code for showing a new form:
NewContactForm contact = new NewContactForm();
contact.TopLevel = true;
contact.ShowInTaskbar = false;
contact.ShowDialog();
RefreshForm();
FillGridView();
I have changed the contactToEdit object's properties and want to save changes. So:
public void UpdateContact(Contact contactToEdit)
{
db.Contacts.ApplyCurrentValues(contactToEdit);
db.SaveChanges();
}
Now I want to show the list of contacts using this code which is in the FillGridView():
db.Contacts.ToList();
Am I missing some code? I even used db.AcceptAllChanges() but useless