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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:58:56+00:00 2026-05-28T19:58:56+00:00

I am developing a simple class that maps any Tuples from database, by convention,

  • 0

I am developing a simple class that maps any Tuples from database, by convention, to CLR objects.

Here in my work, i cannot use EntityFramework, because database is giant and we have splitted models and is impossible to cross different contexts.

So i started develop my own ORM mapper, that generate insert, update and delete commands.
i am trying to develop the select method, that generates select CMD.

This method receives a Expression<T, bool> filter by parameter that i want to filter the data.

One thing that i really want to use is something like:

int value = 1;
int valu2 = 40;

mapper.Select<MyEntity>(m => m.id> value && m.id<= value2);

The big problem is that filter.body.toString() generates a string as is, and, what i really want to do is to replace the values of “value” and “value2” by their values declared on their variables…

Someone can give me a light?

Really Thanks to all!

  • 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-28T19:58:58+00:00Added an answer on May 28, 2026 at 7:58 pm

    I parsed the expr tree in a simple manner, just to build the filter.

    Here’s how i did it.

    private static String ParseFilter(Expression expr)
        {
            return ParseFilter(expr, new ExpressionUtilFilterClass()).data.ToString();
        }
    
        // Recursive algorithm
        private
        static
        ExpressionUtilFilterClass                            // Return type
        ParseFilter(
            Expression expr,
            ExpressionUtilFilterClass info          // Used to pass information in recursive manner
        )
        {
    
            Type exprType = expr.GetType();
    
            if ( exprType != typeof(BinaryExpression) && exprType != typeof(MemberExpression) && exprType != typeof(ConstantExpression) )
                throw new InvalidOperationException("unsupported filter");
    
    
            if ( exprType == typeof(BinaryExpression) )
            {
                //
                // We have 2 expressions (left and right)
                // 
    
                BinaryExpression bExpr = (BinaryExpression)expr;
                ExpressionUtilFilterClass recursion;
    
                StringBuilder subOperation = new StringBuilder();
                recursion = ParseFilter(bExpr.Left, info);              // Go left in depth - we don't know the type yet
    
                subOperation.Append("( ");
                subOperation.Append(recursion.data);
                subOperation.Append(" ");
    
                subOperation.Append(_expressionOperator[bExpr.NodeType]);
                subOperation.Append(" ");
    
                recursion = ParseFilter(bExpr.Right, recursion);               // Pass reference that contains type information!
    
                subOperation.Append(recursion.data);
                subOperation.Append(" )");
    
                // Affect data subpart and pass to upper caller
                recursion.data = subOperation.ToString();
    
                return recursion;
            }
    
            else
            {
                MemberExpression mExpr;
                ParameterExpression pExpr;
                ConstantExpression cExpr;
    
                //
                // We need distinct if we are accessing to capturated variables (need map to sql) or constant variables
                //
    
                if ( ( mExpr = expr as MemberExpression ) != null )
                {
                    if ( ( pExpr = ( mExpr.Expression as ParameterExpression ) ) != null )
                    {
                        info.parameterType = mExpr.Expression.Type;        // Type of parameter (must be untouched)
                        info.data = GetMappingForProperty(info.parameterType, mExpr.Member.Name);                     // Must have a map to SQL (criar metodo que faz mapeamento)!!!!!!!!!!!!!!!!!
    
                        return info;
                    }
                    else
                    {
                        cExpr = (ConstantExpression)mExpr.Expression;
    
                        object obj = cExpr.Value;               // Get anonymous object
                        string objField = mExpr.Member.Name;
    
                        FieldInfo value = obj.GetType().GetField(objField);  // Read native value
                        string nativeData = value.GetValue(obj).ToString();
    
                        info.data = nativeData;
                        return info;
                    }
                }
                else
                {
                    cExpr = (ConstantExpression)expr;
                    string nativeData = cExpr.Value.ToString();
    
                    info.data = nativeData;
                    return info;
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a simple translator from MathML to Latex, using Lex and Yacc.
I'm developing simple Windows Service sending and receiving data from remote web service. I
At work, we are developing an PHP application that would be later re-programmed into
I am developing a simple web application which contains these 3 components: client that
I'm developing something like a simple and purpose-specific cms. I'm using a db class
Here's the situation: I'm developing a simple application with the following structure: FormMain (startup
Suppose we are developing class which implements simple CRUD operations for working with DB.
I'm developing a simple container class for C++ and I realized it would be
I am developing an Android App that gets some data from a web server,
I'm developing a twisted.web server - it consists of some resources that apart from

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.