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,447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

710 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