title: how to return selected columns based on user choice
body: <p>I'm trying to limit which fields are returned by an API based on a parameter called fields which I accept multiple strings doing this</p>
  
  <p>private readonly string[] fields;</p>
  
  <pre><code>public string[] SelectiveSerializer(string fields)
  {
      string[] _fields;
      var fieldColl = fields.Split(',');
      _fields = fieldColl
          .Select(f =&gt; f.ToLower().Trim())
          .ToArray();
      return _fields;
  
  }
  </code></pre>
  
  <p>I want to be able to choose what I return based on whatever the user gives me in _fields. Normal way to do it:</p>
  
  <pre><code> var linq = (from entity in db.users
               where entity.ID== id
                &amp;&amp; entity.ON== false
               select( new {
               ID = entity.ID,
               FirstName = entity.FirstName,
               LastName =entity.LastName,
               FotherName = entity.FotherName
               }).ToList();
  </code></pre>
  
  <p>but here I have to specify the fields in Select (ID, FirstName ..etc), which I want it to be dynamic based on what fields[] has. Is there a way to do this?</p>
  
  <p>sort of this (which is wrong):</p>
  
  <pre><code>var linq = (from entity in db.users
               where entity.ID== id
                &amp;&amp; entity.ON== false
               select( new {
               foreach (string s in _fields)
               {
                      entity.s;
               }
               }).ToList();
  </code></pre>