title: Why my LINQ expression do not work in LINQ to SQL?
body: <pre><code>private System.Linq.Expressions.Expression&lt;Func&lt;ActionLogs, bool&gt;&gt; GetExpression()
  {
      Expression&lt;Func&lt;ActionLogs, bool&gt;&gt; expr = w =&gt; w.ID != -1;
      if (ActionDate != null)
      {
          Expression&lt;Func&lt;ActionLogs, bool&gt;&gt; byDate = w =&gt; w.DateAction == ActionDate;
          var body = Expression.AndAlso(expr.Body, byDate.Body);
          expr = Expression.Lambda&lt;Func&lt;ActionLogs, bool&gt;&gt;(body, expr.Parameters[0]);
      }
  
      if (ActionType != ActionTypeEnum.Empty)
      {
          Expression&lt;Func&lt;ActionLogs, bool&gt;&gt; byActionType = w =&gt; w.ActionTypeID == (int)ActionType;
          var body = Expression.AndAlso(expr.Body, byActionType.Body);
          expr = Expression.Lambda&lt;Func&lt;ActionLogs, bool&gt;&gt;(body, expr.Parameters[0]);
      }
  
      if (!String.IsNullOrWhiteSpace(AuthorLogin))
      {
          Expression&lt;Func&lt;ActionLogs, bool&gt;&gt; byLogin = w =&gt; w.User.LoginName == AuthorLogin;
          var body = Expression.AndAlso(expr.Body, byLogin.Body);
          expr = Expression.Lambda&lt;Func&lt;ActionLogs, bool&gt;&gt;(body, expr.Parameters[0]);            
      }
  
      if (!String.IsNullOrWhiteSpace(AdditionalInfo))
      {
          Expression&lt;Func&lt;ActionLogs, bool&gt;&gt; byAdditionalInfo = w =&gt; w.DescriptionText.Contains(AdditionalInfo);
          var body = Expression.AndAlso(expr.Body, byAdditionalInfo.Body);
          expr = Expression.Lambda&lt;Func&lt;ActionLogs, bool&gt;&gt;(body, expr.Parameters[0]);
      }
  
      return expr;
  }
  </code></pre>
  
  <p>This is the function that generate my expression.</p>
  
  <p>and when i do this:</p>
  
  <pre><code> System.Linq.Expressions.Expression&lt;Func&lt;ActionLogs, bool&gt;&gt; expr = GetExpression(); 
   result = blablabla.Where(expr);
  </code></pre>
  
  <p>It says to me that The parameter 'w' is not in scope.</p>
  
  <p>So the question is, how i can generate my expression, that depends on something i need, and paste it into LINQ to SQL query?</p>