title: How to get dynamic column data linq
body: <p>I have following code,</p>
  <pre><code>public List&lt;MemberDto&gt; GetMembers(out int rowCount,int pageIndex,int pageSize,  string seachColumn = &quot;&quot;, string searchTerm = &quot;&quot;, string sortBy = &quot;&quot;, string sortDiection = &quot;&quot;)
  {
      var members = (from m in context.Members
                     where (string.IsNullOrEmpty(searchTerm) || m.MemberNumber.Equals(searchTerm))
                           || (string.IsNullOrEmpty(searchTerm) || m.LastName.Equals(searchTerm))
                     select m).AsEnumerable();
                     
      if (!string.IsNullOrEmpty(sortBy))
      {
          PropertyDescriptor prop = TypeDescriptor.GetProperties(typeof(EFModel.ClientData.Member)).Find(sortBy, true);
          members = (sortDiection.ToLower() == &quot;descnding&quot;) ? members.OrderByDescending(x =&gt; prop.GetValue(x)).ToList() : members.OrderBy(x =&gt; prop.GetValue(x)).ToList();
      }
  
      rowCount =  (!string.IsNullOrEmpty(searchTerm)) ? members.Count() : rowCount = context.Members.Count() ;
      
      members = members.Skip(pageIndex).Take(pageSize).ToList();
  
      List&lt;MemberDto&gt; memberDtos = new List&lt;MemberDto&gt;();
      mapper.Map(members, memberDtos);
      return memberDtos;
  }
  </code></pre>
  <p>In the above code, I <code>seachColumn</code> value can be (&quot;<code>a</code>&quot;,&quot;<code>b</code>&quot;,or &quot;&quot;). When <code>seachColumn</code> = &quot;<code>a</code>&quot; I need to search table data by column <code>MemberNumber</code> based on <code>searchTerm</code> value</p>
  <p>When <code>seachColumn</code> = &quot;<code>b</code>&quot; I need to search table data by column <code>LastName</code>. based on <code>searchTerm</code> value</p>
  <p>to achieve that I wrote following code.</p>
  <pre><code>if(seachBy == &quot;a&quot;)
  {
      var sa = (from m in context.Members
                where (string.IsNullOrEmpty(searchTerm) || m.MemberNumber.Equals(searchTerm))
                select m).AsEnumerable();
  }
  else if (seachBy == &quot;b&quot;)
  {
      var sa = (from m in context.Members
                where (string.IsNullOrEmpty(searchTerm) || m.LastName.Equals(searchTerm))
                select m).AsEnumerable();
  }
  </code></pre>
  <p>I know, I tried code is bit fool. Have any proper way to do this?</p>