Solved

MVVM EntityFramework 4.1 Master-Details. How can i update an ObservableCollection<T> when T is saved using EF and Repository+UOW

Posted on 2013-01-02
2
1,432 Views
Last Modified: 2013-01-03
I have a View that has a listbox whose ItemsSource is an ObservableCollection<T>.
T is a ViewModel (called PersonViewModel) wrapping a poco class (called Person). The PersonViewModel has a SaveCommand and Validation code.

The ListBox selected item is used as the Datacontext for a details view.
The details view shows the single (selected) PersonViewModel and uses the SaveCommand to save any changes, made in the details view, to the wrapped person poco.

The Save command will save the data to SqlServer database using repository Insert, and saving changes the entitys state from Modified to Unchanged.

This doesn't seem to update the ObservableCollection because when I press the Save button again, the entity can be saved again (because its state in the ObservableCollection remains as Modified).

Can you give me any pointers re how to keep the state of ObservableCollection of Person entities synchronized with what the Context thinks is happening.
0
Comment
Question by:quentinA
2 Comments
 
LVL 16

Accepted Solution

by:
Imran Javed Zia earned 500 total points
ID: 38739525
Hi,

Make a seprate ViewMode for binding and then add List/Observable collection in that

public class MainVM
{
ObservableCollection<Person> Persons {get; set}
Person SelectedPerson {get; set;}
//other commands and etc
}

Thanks
0
 

Author Closing Comment

by:quentinA
ID: 38740256
Thanks.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now