title: Expression Tree parsing, variables ends up as constants
body: <p>So I'm working on a project where I need to parse an expression tree. I got most of the things working, but I've run into a bit of a problem.</p>
  
  <p>I've been looking at the other questions on StackOverflow on Expression Trees, but can't seem to find an answer to my question, so here goes.</p>
  
  <p>My problem is the difference (or lack of) between constants and variables. Let me start off with an example:</p>
  
  <pre><code>user =&gt; user.Email == email
  </code></pre>
  
  <p>This is clearly not a constant but a variable, but this ends up being a ConstantExpression somewhere in the expression tree. If you take a look at the expression itself, it looks a bit odd:</p>
  
  <pre><code>Expression = {value(stORM.Web.Security.User+&lt;&gt;c__DisplayClassa)}
  </code></pre>
  
  <p>If we take another example:</p>
  
  <pre><code>task =&gt; task.Status != TaskStatus.Done &amp;&amp; t.Status != TaskStatus.Failed
  </code></pre>
  
  <p>Here I'm using an ENUM (TaskStatus).</p>
  
  <p>So my problem is that in the tree parsing I seem to end up with a ConstantExpression in both cases, and I really need to be able to tell them apart. These are just examples, so what I'm asking is a generic way of telling these two types of expression from each other, so I can handle then in 2 different ways in my parsing.</p>
  
  <p>EDIT: okay, my examples might not be clear, so I'll try again. First example:</p>
  
  <p>User user = db.Search &lt; User > (u => u.Email == email);</p>
  
  <p>I'm trying to find a user with the given e-mail address. I'm parsing this into a stored procedure, but that's besides the point I guess.</p>
  
  <p>Second example:</p>
  
  <p>IList &lt; Task > tasks = db.Search(t => t.Status != TaskStatus.Done &amp;&amp; t.Status != TaskStatus.Failed);</p>
  
  <p>And here I'm trying to locate all tasks with a status different from Done and Failed.
  Again this is being parsing into a stored procedure. In the first example my code needs to determine that the stored procedure needs a input parameter, the value of the email variable. In the second example I don't need any input parameters, I just need to create the SQL for selecting task with a status different from Done and Failed.</p>
  
  <p>Thanks again</p>