title: How to get Property name from MethodCallExpression?
body: <p>I'm trying to call a method with an Expression, and return a string for building a sql query.</p>
  
  <p>the call is simple</p>
  
  <pre><code>var actualUsers = db.Query&lt;UserModel&gt;( u =&gt; u.FirstName.Contains( "ues" ) &amp;&amp; u.LastName == "" );
  </code></pre>
  
  <p>The in my evaluater, I'm able to get <code>"LastName = ''"</code> very easily, using a BinaryExpression evaluator.</p>
  
  <p>However, when I try to get "FirstName" out of the <code>MethodCalLExpression</code>, the closest I can get is <code>u.FirstName</code> by using <code>expression.Object.ToString();</code></p>
  
  <p>What is the right way to get the property name of the MethodCallExpression?</p>
  
  <p>Here's the method I've got so far.</p>
  
  <pre><code>    public static IList&lt;TModel&gt; Query&lt;TModel&gt; ( this IDbProvider iDbProvider, Expression&lt;Func&lt;TModel, object&gt;&gt; exp ) where TModel : class, new()
      {
          // SELECT * FROM [Users] WHERE FirstName LIKE '%ues%'
          // Should return the "Guest" user.
  
          var sqlExpression = GetSqlExpression( exp.Body );
          return // ....
      }
  
      private static string GetSqlExpression ( Expression expression )
      {
          if ( expression is MethodCallExpression )
          {
              return GetMethodCallOperator( ( MethodCallExpression )expression );
          }
          // more crap...
      }
  
      private static string GetMethodCallOperator ( MethodCallExpression expression )
      {
          var lambda = Expression.Lambda( expression.Arguments[0] );
          var compiledExpression = lambda.Compile().DynamicInvoke();
  
  
          var commandText = string.Empty;
          var key = expression.Object.ToString(); // "u.FirstName" -- should just be "FirstName"
          var value = compiledExpression.ToString(); // "ues"
          switch ( expression.Method.Name )
          {
              case "Contains":
                  commandText = "[{0}] LIKE '%{1}%'";
                  break;
          }
  
          // return "[FirstName] LIKE '%ues%'";
          return string.Format(commandText ,key, value);
      }
  </code></pre>