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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:39:59+00:00 2026-06-14T03:39:59+00:00

I want to write a generic extension method that will return a specified set

  • 0

I want to write a generic extension method that will return a specified set of objects, according to a user-defined filter, with a signature like so:

public static IEnumerable<T> GetObjects<T>(this ObjectSet<T> os, string fieldName, object value) where T : EntityObject {}

Of course, we could change the signature to handle multiple filters, but let’s first focus on the single field filter.

How would you write a Linq query that does 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-14T03:40:00+00:00Added an answer on June 14, 2026 at 3:40 am

    You need to dynamically build lambda-expression and call Queryable.Where for os with this expression:

    public static IQueryable<T> GetObjects<T>(this ObjectSet<T> os, 
                                              string fieldName, object value)
    {
        var param = Expression.Parameter(typeof(T), "x");
        var body = Expression.Equal(
            Expression.PropertyOrField(param, fieldName), 
            Expression.Constant(value, value.GetType()));
        var lambda = Expression.Lambda<Func<T, bool>>(body, param);
        return os.Where(lambda);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write generic method that checks if a given entity is in
I want to write a generic (C/C++) library that I will use to develop
I want to write a generic averaging algorithm. That is, for any type T
I want to write a generic function that has a constraint on the type.
I want to write a generic helper method: def using(closeable: [B has close() method],
I want to write a generic class that should be casted to itself with
How can I write a generic method that can take a Nullable object to
I'm trying to write generic method to cast types. I want write something like
I want to be able to write extension methods so that I can say:
Is it possible to add an extension method to a generic class that is

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.