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,443 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding bootstrap to only Content page and NOT master page 1 50
RLDC Reporting in Visual studio 11 30
SQL Query Help Top 1 and Distinct? 6 36
How to read text with RegEx... 2 25
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

828 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