Обновить DataSource после SaveChange не работает - PullRequest
2 голосов
/ 29 июня 2011

Я добавил данные в ObjectSet и сделал SaveChanges на ObjectContext.Но новые данные не отображаются в DataGrid!

Код: bsWork.DataSource = Program.EC.Addresses; ... Address newAdr = new Address(); //change properties newAdr ... Program.EC.Addresses.AddObject(newAdr); Program.EC.SaveChanges(SaveOptions.AcceptAllChangesAfterSave); Как обновить данные или просмотреть новые данные?

UPD: Решение

... bsWork.Add(newAdr); Program.EC.SaveChanges(SaveOptions.AcceptAllChangesAfterSave); ...

1 Ответ

1 голос
/ 29 июня 2011

Я надеюсь, что этот код может быть полезным для вас.<pre> try { // Try to save changes, which may cause a conflict. int num = context.SaveChanges(); Console.WriteLine("No conflicts. " + num.ToString() + " updates saved."); } catch (OptimisticConcurrencyException) { // Resolve the concurrency conflict by refreshing the // object context before re-saving changes. context.Refresh(RefreshMode.ClientWins, orders);</p> <pre><code>// Save changes. context.SaveChanges(); Console.WriteLine("OptimisticConcurrencyException " + "handled and changes saved");

}

...