title: How to write LINQ query with column name as parameter still in a type safe way
body: <p>I am seeking help on how to achieve this with LINQ in a type safe way.</p>
  
  <p>I need to perform search on "Performance" table with many columns. Based on the criteria specified for search I need to pick columns and perform search on those columns with given values. </p>
  
  <pre><code>private static IQueryable&lt;Investment&gt; PerformanceSearch(IQueryable&lt;Investment&gt; investments, **??? searchColumn**, double minValue, double maxValue)
  {
    var entity = ExtendedEntities.Current;
  
    investments = from inv in entity.Investments 
                  join performance in entity.Performances on inv.InvestmentID equals perfromance.InvestmentID
                  where **performance.searchColumn** &gt;= minValue &amp;&amp; **performance.searchColumn** = maxValue
    return investments;
  }
  </code></pre>
  
  <p>Now I am seeking your help on:</p>
  
  <ol>
  <li><p>How to pass column "searchColumn" to this method in a type safe way? I was thinking of creating a dictionary object to accommodate some way to maintain column names from entity framework. But not sure how to achieve this.</p></li>
  <li><p>How to perform LINQ query using the columnName passed and applying where clause.</p></li>
  </ol>
  
  <p>I cannot use If Else or Switch case as below is a list of possible search columns...</p>
  
  <pre><code>/*
   * Search Columns can be:
   *      "Return1Month", "Return2Months", "Return3Months", ... almost 10 more and
   *      "Risk1Month", "Risk2Months", "Risk3Months", ... almost 10 more and
   *      "TrackingError1Month", "TrackingError2Months", "TrackingError3Months", ... almost 10 more and
   *      2 more similar set of columns ... 
   */
  </code></pre>
  
  <p>I spent time on Stackoverflow, Microsoft and other blogs and considered using Dynamic LINQ but it's not type safe. It <em>seems</em> that it is achievable using expressions but couldn't get that working.</p>
  
  <p>Any advice is appreciated.</p>
  
  <p><strong>EDIT -</strong></p>
  
  <p><strong>Another item to mention - all search columns are present in "performance" table.</strong></p>