I have some master-detail classes based in large part on Josh Smith's msdn article. Its great code, especially for an example, but leaves me wondering how best to handle situations where you want some subset of a repository.
So Josh has a class called AllCustomersViewModel, and code something like:
public AllCustomersViewModel(CustomerRepository customerRepository)
{
if (customerRepository == null) throw new ArgumentNullException("customerRepository");
// Populate the AllCustomers collection with CustomerViewModels.
_allCustomers = _customerRepository
.GetCustomers()
.Select(cust => new CustomerViewModel(cust, _customerRepository))
.ToList();
}
How do you solve a situation where you want PreferredCustomers, ExCustomers, LocalCustomers, etc, etc??
His code suggests to me a ViewModel class for each, with the filtering of the repository hard-coded in that class.
Or else a way to pass an optional filter into the ViewModel along with the repository?
How does your code solve this particular problem?
As an aside, does anyone have links or good examples showing how to use SpeciaficationPattern or IQueryable to solve issues like this?
Cheers,
Berryl