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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:00:36+00:00 2026-05-14T01:00:36+00:00

Implemented a generic repository with several Methods. One of those is this: public IEnumerable<T>

  • 0

Implemented a generic repository with several Methods. One of those is this:

public IEnumerable<T> Find(Expression<Func<T, bool>> where)
        {
            return _objectSet.Where(where);
        }

Given <T> to be <Culture> it is easy to call this like this:

Expression<Func<Culture, bool>> whereClause = c => c.CultureId > 4 ;

return cultureRepository.Find(whereClause).AsQueryable();

But now i see (realize) that this kind of quering is “limiting only to one criteria”.
What i would like to do is this:

in the above example c is of type Culture. Culture has several properties like CultureId, Name, Displayname,…
How would i express the following:
CultureId > 4 and Name.contains(‘de’) and in another execution
Name.contains(‘us’) and Displayname.contains(‘ca’) and ….

Those queries should be created dynamically.
I had a look in Expression trees (as i thought this to be a solution to my problem – btw i never used them before) but i cannot find anything which points to my requirement.

How can this be costructed?

Thanks in advance

  • 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-14T01:00:36+00:00Added an answer on May 14, 2026 at 1:00 am

    Codeka gave me a hint for re-thinking my statement, regarding this limitation to one parameter.

    Turns out it very easy to implement a scenario with all the properties we want to query, which have values. For example if the Cutlure type is defined with 3 properties

    Name string

    Displayname string

    CultureId int

    than one can implement a Filter-Expression like this

    Expression<Func<Culture, bool>> whereClause = c => (
                    (!String.IsNullOrEmpty(FilterCulture.Name) ? c.Name.Contains(FilterCulture.Name) : true) &&
                    (!String.IsNullOrEmpty(FilterCulture.Displayname) ? c.Displayname.Contains(FilterCulture.Displayname) : true) &&
                    (FilterCulture.CultureId > 0 ? c.CultureId == FilterCulture.CultureId : true)
                    );
    

    As you can see i ‘m using the && operator between each property to narrow the results (one could use the || to widen the results – thus implementing OR).

    Thank you again codeka !

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

Sidebar

Related Questions

I have implemented the repository pattern using the following generic interface. public interface IRepository<T>
I am trying to implement a generic repository pattern. I found this site which
I'm trying to implement the repository pattern using a generic repository like the one
I have a generic DAO class that looks like this: public class GenericDaoJpa <T
For Code First CTP 3 and 4 I had a generic repository pattern implemented
I'm trying to implement a Generic Repository. This is what I've got so far
I have implemented Generic repository which only depends on IUnitOfWork (in Infrastructure.Repositories Library) and
I lately wanted to learn more about generic methods and created several examples, but
I am trying to implement generic repository pattern using LINQ to SQL data context.
When using ASP.NET MVC plus Entity Framework, and trying to implement a generic repository

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.