Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5949839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:18:28+00:00 2026-05-22T17:18:28+00:00

I have some master-detail classes based in large part on Josh Smith’s msdn article

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:18:29+00:00Added an answer on May 22, 2026 at 5:18 pm

    One option (and probably the cleanest) is to simply add those methods to the CustomerRepository – e.g. GetPreferredCustomers(), GetLocalCustomers() etc.

    Also, you should really be working against abstractions, so should pass an ICustomerRepository to your view model constructor. This decouples your view model code from your concrete customer repository (in this case one that reads from an XML file), and makes it easy to swap out implementations, e.g. for unit testing.

    The other option, as you mention, is for your repository to expose IQueryable<T>. If you are happy to be tied into IQueryable, and are confident that any data access implementation is going to support a LINQ provider, then that provides good flexibility. See here for more info.

    Personally, I prefer the first option, particularly for larger scale applications.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the basic Master / Detail Views working great with the default ASP.NET
I have some ASP.NET Master Pages located in one assembly. I need to use
I have some data of the form Key ID Link 1 MASTER 123 2
I have some code that I am putting in the code-behind of a master
I have a branch called experiment. git checkout master echo 'some changes' > a.txt
I have a view using a master page that contains some javascript that needs
I have two branches master and exp i tried to cherry pick some of
I have some UI in VB 2005 that looks great in XP Style, but
I have two tables: OutputPackages (master) |PackageID| OutputItems (detail) |ItemID|PackageID| OutputItems has an index
Look, I have these pretty simple model Master-Detail: Hand is master of Fingers (finger

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.