title: C# Linq Filter IEnumerable dynamic property and value
body: <pre><code>public class Sample
  {
      public int Id { get; set; }
      public string Description { get; set; }
      public DateTime EffectiveDate { get; set; }
  }
  
  IEnumerable&lt;Sample&gt; sampleList;
  //Populate the list
  </code></pre>
  <p>Now I want to filter the list some times by &quot;Id&quot; property, sometimes &quot;Description&quot; property. Just want to pass the property name (filterColumn) and property value (filterValue) both as strings.</p>
  <p>I tried the following:</p>
  <pre><code>IEnumerable&lt;Sample&gt; result = sampleList.Where(x =&gt; x.GetType().GetProperty(filterColumn).Name == filterValue);
  </code></pre>
  <p>and</p>
  <pre><code>string whereQuery = string.Format(&quot; {0} = \&quot;{1}\&quot;&quot;, filterColumn, filterValue);
  IEnumerable&lt;Sample&gt; result = sampleList.AsQueryable().Where(whereQuery);
  </code></pre>
  <p>The second option works, if i pass the filterColumn as &quot;Description&quot;, but throws incompatible '=' operator between string and int error when &quot;Id&quot; is passed as filterColumn and some filterValue like &quot;1&quot;.</p>
  <p>Appreciate any help. Thanks</p>