I’m attempting the example from the excellent “How Do I” video for MVVM by Todd Miranda found in MSDN.
I’m trying to adapt the example for my learning purpose.
-
In the example, he has a ViewModel called EmployeeListViewModel. Now if I want to include Departments, should I create another ViewModel such as DepartmentListViewModel?
-
The example has EmployeeRepository as the Data Source. In my case, I’m trying to use an Entity object as the datasource (Employees.edmx in Model folder and EmployeeRepository.cs in DataAccess folder). If I want to display the list of Departments, should I create a separate class called DepartmentRepository and put all department related method definitions there?
-
What if I want to retrieve the employee name and their department’s name together? Where should I place the methods for this?
I’m very new to WPF and MVVM and please let me know if any of the above needs to be re-phrased.
Thank you for all the help.
It depends, as every pattern is more like and idea/concept than something you need to follow strictly. By saying this you will notice that sometimes yes, is advisable to use a class for each ViewModel or maybe use a generic ViewModel if applies.
I know it’s hard because I was (and still I am) in the same position as yours.
In question 2, What I do sometimes is to Retrieve and IQueryable and then “translate” the returning object to a ViewModel. Repositories/Domain should not know nothing about ViewModels, since is just a presentation thing.
Answering point 3, if you need to bind a control with Employee and Departments together,
Maybe you can do something like this:
Hope this clarifies your doubts.