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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:35:22+00:00 2026-05-16T03:35:22+00:00

I have a method which have this signature public static IList<T> GetBy<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression)

  • 0

I have a method which have this signature

public static IList<T> GetBy<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression)

I use to pass lambda expressions and make search restriction in nhibernate by retrieving data from expressiontree.

So when class user pass something like :

c => c.fullName == "John" && c.lastName == "Smith" && c.lastName != "" || c.fullName != ""  && c.Age > 18

I get to read this structure from expression tree, that way I have a full intellisense way to provide searching criteria

In other words: I need to pass searching criteria to data access layer (Nhibernate)

So I need to extract criteria from expression tree and then pass it to n hibernate by example :

c=>c.fullname = "John" 

I will extract the following information from the expression tree :

propertyname = fullname , value = "John" , restrictiontype = "equality" 

and then pass this info to nhibernate as following :

ICriteria crit = session.CreateCriteria(typeof(T));
                    crit.Add(Restrictions.Eq(propretyName, value));
    IList<T> list = crit.Add(List<T>())
                    return list;

Any way the problem is it’s really hard to read from expressiontree, so I was wondering if you guys have any easy way of maybe iterating inside expressiontree to pull data, or maybe you guys have some code to retrieve data from ExpressionTree.

  • 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-16T03:35:22+00:00Added an answer on May 16, 2026 at 3:35 am

    Here is some code that retrieves the information you mentioned. I’m sure you can extend this to include additional information you might be looking for.

    public class Criterion
    {
        public string PropertyName;
        public object Value;
        public ExpressionType RestrictionType;
    }
    
    [....]
    
    public static IEnumerable<Criterion> GetCriteria<T>(Expression<Func<T, bool>> expression)
    {
        return getCriteria<T>(expression.Body);
    }
    private static IEnumerable<Criterion> getCriteria<T>(Expression expression)
    {
        if (expression is BinaryExpression)
        {
            var bin = (BinaryExpression) expression;
            if (bin.NodeType == ExpressionType.And || bin.NodeType == ExpressionType.AndAlso ||
                bin.NodeType == ExpressionType.Or || bin.NodeType == ExpressionType.OrElse)
                return getCriteria<T>(bin.Left).Concat(getCriteria<T>(bin.Right));
    
            if (bin.Left is MemberExpression)
            {
                var me = (MemberExpression) bin.Left;
                if (!(bin.Right is ConstantExpression))
                    throw new InvalidOperationException("Constant expected in criterion: " + bin.ToString());
                return new[] { new Criterion {
                    PropertyName = me.Member.Name,
                    Value = ((ConstantExpression) bin.Right).Value,
                    RestrictionType = bin.NodeType
                } };
            }
    
            throw new InvalidOperationException("Unsupported binary operator: " + bin.NodeType);
        }
    
        throw new InvalidOperationException("Unsupported expression type: " + expression.GetType().Name);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have static method which plays music. How to return value from this method
I have a static method like this public static string DoSomethingToString(string UntrustedString) { //parse
Aloha I have a method with (pseudo) signature: public static T Parse<T>(string datadictionary) where
I have an extension method with the following signature (in BuildServerExtensions class):: public static
I am using a method that has the following signature: public static bool TryAuthenticate(string
I have a method which runs this: Track* track = [[Track alloc] init:[obj objectForKey:@PersistentID]
I have this method which will remove all rows from a table but I
So I have this method which will take an ArrayList of Integers, I compare
I have this method which does certain checks and applies a color code on
I have a method which is list my items from a server. Therefore, this

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.