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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:11:42+00:00 2026-06-15T14:11:42+00:00

I want to pass dynamic lambda expressions to the function below, but I’m not

  • 0

I want to pass dynamic lambda expressions to the function below, but I’m not sure how to define the .Take() or .OrderByDescending() on the expression object.
If I want to call the function below, then I want to be able to do this:

dbprovider.Query = (x => x.ConfigurationReference == "172.16.59.175")
                   .Take(100)
                   .OrderByDescending(x.Date)
FindEntities(db, dbprovider.Query)

But I can’t (this syntax is invalid). Any ideas?

public static List<T> FindEntities<T>(TrackingDataContext dataContext, System.Linq.Expressions.Expression<Func<T, bool>> find) where T : class
{
    try
    {
        var val = dataContext.GetTable<T>().Where(find).ToList<T>();
        return val;
    }
    catch (Exception ex)
    {
        throw ex;
    }
}
  • 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-15T14:11:44+00:00Added an answer on June 15, 2026 at 2:11 pm

    The parameter is of type:

    System.Linq.Expressions.Expression<Func<T, bool>> find
    

    That means it can take a predicate (the “where” clause), and only a predicate. Thus the only bit you can pass in there is the filter:

    x => x.ConfigurationReference == "172.16.59.175"
    

    To do what you want, you would need to add the rest of the code in FindEntities, so that it becomes:

    var val = dataContext.GetTable<T>().Where(find)
                  .OrderByDescending(x => x.Date).Take(100).ToList<T>();
    

    (note also that the Take should really be after the OrderByDescending)

    One way you could do that would be:

    public static List<T> FindEntities<T>(TrackingDataContext dataContext,
        System.Linq.Expressions.Expression<Func<T, bool>> find,
        Func<IQueryable<T>, IQueryable<T>> additonalProcessing = null
    ) where T : class
    {
        var query = dataContext.GetTable<T>().Where(find);
        if(additonalProcessing != null) query = additonalProcessing(query);
        return query.ToList<T>();
    }
    

    and call:

    var data = FindEntities(db, x => x.ConfigurationReference == "172.16.58.175",
        q => q.OrderByDescending(x => x.Date).Take(100));
    

    However, frankly I’m not sure what the point of this would be… the caller could do all of that themselves locally more conveniently, without using FindEntities at all. Just:

    var data = db.GetTable<T>()
                 .Where(x => x.ConfigurationReference == "172.16.58.175")
                 .OrderByDescending(x => x.Date).Take(100).ToList(); 
    

    or even:

    var data = db.SomeTable
                 .Where(x => x.ConfigurationReference == "172.16.58.175")
                 .OrderByDescending(x => x.Date).Take(100).ToList();
    

    or just:

    var data = (from row in db.SomeTable
                where row.ConfigurationReference == "172.16.58.175"
                orderby row.Date descending
                select row).Take(100).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass a dynamic parameter with qTip, but it fails. my_ajax_controller.php just
I want pass a class-instace to a method of an other and be sure
I want to pass data from second tab to first tab using delegates.But delegate
I have this 2d dynamic array and I want to pass it to a
i want to create dynamic banner rotater wih php ajax i want to pass
I want to pass some dynamic paramters to jquery onClick event. Before, I used
I want to pass JSON (a small amount of which will be dynamic) from
I want to call a dynamic JSP page and pass data to it so
I want to use Linq expression for some dynamic features. I need And, Or
I want pass dynamic URL of excel to OPENROWSET. NOTE - I am passing

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.