简体   繁体   中英

Entity Framework - Refresh without losing changes

I am trying to implement a way to either shelve changes to an EF6 context while I dispose and reload it or to refresh the context without losing changes.

I have a lot of scenarios where the user is updating a foreign key relationship on an object and they need to refresh the combobox on the form with new data without resetting all of their work.

For example: The object starts as follows:

Foo.Name = "Joe"
Foo.Bar = SomeBar

The user wants to change the object to

Foo.Name = "Sam"
Foo.Bar = NewBar

But they can't because NewBar needs to be created. So, the user opens the Bar creation form (which is using a different EF context) and makes NewBar . When they return to the Foo edit form, they expect to see NewBar in the dropdown, but it is not there. They can close and reopen the form to see NewBar , but now they need to change "Joe" to "Sam" again.

How can I get around this or implement a pattern that makes it a non-issue?

This basically turned out to be a non-issue.

I am using a Messenger to notify my contexts when they need to refresh.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM