title: Multiple Conditions in Lambda Expressions at runtime C#
body: <p>I would like to know how to be able to make an Expression tree by inputting more than one parameter</p>
  
  <p>Example:</p>
  
  <pre><code>dataContext.Users.Where(u =&gt; u.username == "Username" &amp;&amp; u.password == "Password")
  </code></pre>
  
  <p>At the moment the code that I did was the following but would like to make more general in regards whether the condition is OR or AND</p>
  
  <pre><code>public Func&lt;TLinqEntity, bool&gt; ANDOnlyParams(string[] paramNames, object[] values)
      {
          List&lt;ParameterExpression&gt; paramList = new List&lt;ParameterExpression&gt;();
          foreach (string param in paramNames)
          {
              paramList.Add(Expression.Parameter(typeof(TLinqEntity), param));
          }
  
          List&lt;LambdaExpression&gt; lexList = new List&lt;LambdaExpression&gt;();
          for (int i = 0; i &lt; paramNames.Length; i++)
          {
              if (i == 0)
              {
                  Expression bodyInner = Expression.Equal(
                                      Expression.Property(
                                          paramList[i], paramNames[i]),
                                          Expression.Constant(values[i]));
                  lexList.Add(Expression.Lambda(bodyInner, paramList[i]));
              }
              else
              {
                  Expression bodyOuter = Expression.And(
                                      Expression.Equal(
                                      Expression.Property(
                                      paramList[i], paramNames[i]),
                                      Expression.Constant(values[i])),
                                      Expression.Invoke(lexList[i - 1], paramList[i]));
                  lexList.Add(Expression.Lambda(bodyOuter, paramList[i]));
              }
          }
  
          return ((Expression&lt;Func&lt;TLinqEntity, bool&gt;&gt;)lexList[lexList.Count - 1]).Compile();
      }
  </code></pre>
  
  <p>Thanks</p>