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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:17:02+00:00 2026-05-22T02:17:02+00:00

I have a question for how to implement multiple criteria for a repository pattern

  • 0

I have a question for how to implement multiple criteria for a repository pattern in ASP.net MVC. Imagine a POCO class in EF4

public class people
{ String Name {get;set;}
float Height {get;set;}
float Weight {get;set;}
int age {get;set;}
....
}

If I build up a repository as IPeopleRepository, what kind of methods should I implement for a multiple criteria search (e.g Age > 30, Height >80). Those criteria would be related to the properties in the class and some of the input could be null. Of course I can write a method like

People SearchPeople (int age, float height.....) 

but I have to judge if every variable would be null and append onto the search queries..

So do you have any good ideas on how to implement this function in EF?

  • 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-22T02:17:03+00:00Added an answer on May 22, 2026 at 2:17 am

    It sounds like your looking for something like the Specification pattern.

    There is a great article involving EF4 / POCO / Repository / Specification pattern here.

    Although i like the pattern, i find it a bit overkill in simple scenarios.

    I ended up using the “pipes and filters” technique – basically IQueryable<T> extension methods on your objects to make your repository code fluent.

    For a search criteria however, i would be tempted to allow the consuming code to supply the predicate, then you don’t have to worry about the parameters.

    So the definition would be like this:

    public People SearchPeople(Expression<Func<People,bool>> predicate)
    {
       return _context.People.SingleOrDefault(predicate);
    }
    

    Then the code simply supplies the predicate.

    var person = _repository.SearchPeople(p => p.Age > 30 && p.Height > 80);
    

    Some people don’t like this technique, as it gives too much “power” to the consumer, because they might supply a predicate like p.Id > 0 and return all the rows in the database.

    To counteract that, provide an optional parameter for maxRows. If it’s not supplied, default to 100 rows.

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

Sidebar

Related Questions

I have this question: Does implementing a custom MembershipProvider class needs you to implement
Actually, this question seems to have two parts: How to implement pattern matching? How
I have a Question class: class Question { public int QuestionNumber { get; set;
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have a question about using streams in .NET to load files from disk.
Take for example a multiple choice question game. You have a MathQuestion and WordQuestion
We have the question is there a performance difference between i++ and ++i in
We have a question with regards to XML-sig and need detail about the optional
I have a question on the best way of exposing an asynchronous remote interface.
I have a question about best practices regarding how one should approach storing complex

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.