Prism-MEF-MVVM: Implementing Masrer Details relationship

Topics: Prism v4 - WPF 4
Feb 9, 2013 at 5:53 AM
Edited Feb 9, 2013 at 6:09 AM
I've asked similar question before in another thread but i couldn't get an answer so i tried to re-shape my
question and drive it from another perspective:
I'm developing LOB application with Model layer/module and Service Layer/Module
then several modules each cover part of the functionality.
Here is analogy for part of my Model classes
 public class Customer
        public string CustomerID { get; set; }
        public string CompanyName { get; set; }
        public string Address { get; set; }
        public string Phone { get; set; }
        public IEnumerable<Order> Orders { get; set; }

 public class Order
        public int OrderID { get; set; }
        public DateTime? OrderDate { get; set; }
        public DateTime? ShippedDate { get; set; }
        public IEnumerable<OrderDetail> OrderDetails { get; set; }

 public class OrderDetail
        public Product Product { get; set; }
        public int Quantity { get; set; }
        public decimal UnitPrice { get; set; }
the model classes are populated by CustomerService
Now i want in one of the modules to:
1-implement this hierarchy (Master-Details Relationship) in MVVM knowing that
i'm using Prism 4 and MEF (Microsoft Extensibility Framework) as IOC Container
2-the Details parts will have their own ViewModel, to enable me to add CRUD operations
3-how to implement CRUD operations w/n details view models

Your help is very much appreciated.
Feb 14, 2013 at 3:07 PM
If you have a single viewmodel that has a colleciton of customers and you have a combobox for example with the list use selectedItem to set SelectedCustomer in view model. Bind the selected customer to your for example DataGrid with its item source={Binding SelectedCustomer.Orders}. When you select the OrdersDatagrid first row set the selecteditem to another property in view model called SelectedOrder. If you bind Selected Order to another Datagrid's ItemsSource=SelectedOrder.orderDetails.

You have one view model that give everything you needed. Of course it will not be a production quality code to just directly bind all easily. For production you may want to filter data based on dates, etc to avoid loading everything from the database.

Hope this helps!