title: C# How To Pass Linq Lambda Parameters to SwitchExpression And Receive Expression<Func<T,object>> in Lambda .Where(...)
body: <p>C# How To Pass Linq Lambda Parameters  to SwitchExpression And Return Expression To .Where(...) Lambda Linq Queryable</p>
  
  <p>i write a linq Lambda query that Who i want use Func That Declare SwitchExpression in this And Use On where(p=>...)
  in this code use predicat , It's like this :</p>
  
  <p>model is : </p>
  
  <pre><code>public class FieldValue
      {
          public virtual int Id { get; set; }
          public virtual string Value { get; set; }
          public virtual int FieldId_fk { get; set; }
          public virtual int TAdvertiesId_fk { get; set; }
      }
  
  var predicateItemTest = LinqKit.PredicateBuilder.True&lt;FieldValue&gt;().And(x =&gt; x.FieldId_fk == 2); //2 is digit for test
  SwitchCase[] cases = new SwitchCase[] {
  new SwitchCase[] { Expression.SwitchCase(Expression.Constant(predicateItemTest), Expression.Constant(2, typeof(int))) } 
  };
  
  SwitchExpression _SwitchExpression = Expression.Switch(Value, Expression.Constant(LinqKit.PredicateBuilder.False&lt;FieldValue&gt;()), //Default Value
   cases);
  
  SwitchCase_Predicate = Expression.Lambda&lt;Func&lt;int, Expression&lt;Func&lt;FieldValue, bool&gt;&gt;&gt;&gt;(_SwitchExpression, Value).Compile();
  </code></pre>
  
  <p>1) First Test :</p>
  
  <pre><code>var FilterResult = _FieldValue.Table.Where(p=&gt;SwitchCase_Predicate(p.FieldId_fk).Compile()).ToList();
  </code></pre>
  
  <p>when call this method and who i want pass parameter to SwitchCase_Predicate(...) it has error because Return Type Is expression and should not pass Dynamic parameters.
  if use like below worked but not allow pass parameter in .where(...) :</p>
  
  <p>2) Second Test :</p>
  
  <pre><code>var FilterResult = _FieldValue.Table.Where(SwitchCase_Predicate(2).Compile()).ToList();
  </code></pre>
  
  <p>how to pass parameter in where(...) like "First Test" and return expression predicat for use in .where(...) correctly</p>
  
  <p>Please help fix this problem.</p>