Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
1,465 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

721 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