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 581697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:36:26+00:00 2026-05-13T14:36:26+00:00

I am considering refactoring a repository I have to improve its flexibility and reduce

  • 0

I am considering refactoring a repository I have to improve its flexibility and reduce the method count.

Where there are the following methods:

Collection GetAllUsersByRole(Role role)
User GetUserByuserName(string userName)

…I would like to have a single method taking a Linq expression:

ICollection GetUsers(Expression e)
{
  //retrieve user collection from store
  //apply expression to collection and return
}

Is this a reasonable approach? Presumably I’d lose some efficiency because the full users collection would need to be retrieved and filtered every time, rather than retrieving a subset of users according to some hard-coded criteria?

Edit: NHibernate provides ORM in my implementation.

  • 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-13T14:36:27+00:00Added an answer on May 13, 2026 at 2:36 pm

    You really want to take an Expression as the argument to that method.

    As far as performance, it really comes down to how far you want to go with it. The simplest method is bringing all the objects into memory and then filtering with the predicate expression.

    On the other hand, you mention some sort of criteria. I have no idea what your back end data system is, but you can take these passed filters and transform them into your criteria. This is essentially what Linq to SQL and Linq to Entities does, but hopefully the range of possibilities you need to support is significantly smaller. If not, it might make sense to switch to one of the ORM tools if you want to take this approach.

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

Sidebar

Related Questions

I have a collection of legacy C code which I'm refactoring to split the
Considering architecture.... I normally have a shopping cart class with addItem and removeItem methods
Considering the following architecture: a base object 'Entity' a derived object 'Entry:Base' and a
Considering you have an MVVM Architecture in WPF like Josh Smith's examples How would
Considering there are so many draconian firewalls in the world, is there any reason
Considering the following data frames : > tail(tot.final) names.id sequence names.reads width.reads names.counts st
Considering the following vector: [1] 1-1694429 2-1546669 3-928598 4-834486 5-802353 6-659439 7-552850 8-516804 9-364061
Considering the following database : Post -> User The entities : class User {
Considering the following two usage scenarios (exactly as you see them, that is, the
Considering the following c code: typedef struct ELE *tree_ptr struct ELE { long val;

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.