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

  • SEARCH
  • Home
  • 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 7809185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:20:57+00:00 2026-06-02T03:20:57+00:00

It seems that every example I find of the repository pattern, the implementation is

  • 0

It seems that every example I find of the repository pattern, the implementation is different in some way. The following are the two examples I mainly find.

interface IProductRepository
{
    IQueryable<Product> FindAll();
}

There is then usually another layer which talks to the repository and calls the FindAll() method and performs any operations such as finding products beginning with the letter ‘s’ or fetching products in a particular category.

The other example I find a lot put all of the find methods into the repository

interface IProductRepository
{
    IEnumerable<Product> GetProductsInCategory(int categoryId);
    IEnumerable<Product> GetProductsStartingWith(string letter);
    IEnumerable<PromoCode> GetProductPromoCodes(int productId);
}

Which path do you recommend I take? Or what are the advantages/disadvantages from each other?

From my understanding having read http://martinfowler.com/eaaCatalog/repository.html the first approach seems to best reflect this?

  • 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-06-02T03:20:59+00:00Added an answer on June 2, 2026 at 3:20 am

    The first one is horrible. IQueryable is like a GOD object. It’s really hard to find a 100% complete implementation of it (even among all OR/Ms). You can expose your ORM directly instead of using it since you’ll probably get a leaky abstraction layer otherwise.

    Joel says it best (text is from the wikipedia article):

    In Spolsky’s article, he calls attention to many examples of abstractions that work most of the time, but where a detail of the underlying complexity cannot be ignored, and thus drives complexity into the software that was supposed to be simplified by the abstraction itself

    Joels blog entry

    The second approach is much easier to implement and to keep the abstraction intact.

    Update

    Your repository is violating Single Responsibility Principle since it got two reasons to change. The first is if the Products API is changed and the other is if the PromoCode API is changed. You should imho use two different repositories like:

    interface IProductRepository
    {
        IEnumerable<Product> FindForCategory(int categoryId);
        IEnumerable<Product> FindAllStartingWith(string letter);
    }
    
    interface IPromoCodeRepository
    {
        IEnumerable<PromoCode> FindForProduct(int productId);
    }
    

    Changed things:

    • I tend to begin methods with Find when several items are returned and Get if a single item is returned.
    • Shorter method names = easier to read.
    • Single responsibility. It’s easier to tell what the classes that use the repositories have for dependencies.

    Small well defined interfaces makes it easier to spot violations of the SOLID principles since classes the break the principles tend to get bloated constructors.

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

Sidebar

Related Questions

It seems like every example I can find of switching between activities involves creating
It seems that every time I want to perform a db query, I have
It seems that every week or so someone posts a question about dates being
I'm working on a project and it seems that every time someone checks out
I am having problems with the google maps API V3. It seems that every
In every benchmark that I found on the web it seems that Ruby is
Pretty much every other editor that isn't a vi descendant (vim, cream, vi-emu) seems
This seems to go against every design guideline. A static method that accepts a
My goal is to understand every single bit of the following example: http://code.google.com/p/google-api-java-client/wiki/AndroidAccountManager I
I use some libraries that I don't want built as part of every project

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.