title: Create a dynamic DTO
body: <p>Im trying to implement a dynamic dto. First there will be a information manager where you can select the fields you want to return by the WebApi.</p>
  
  <p>Later in the api you send a request to an endpoint with  the  DTO's Id you want. This method will recive the info, query it in the db and  obtain the fields that integrate the DTO(dynamic number of fields):</p>
  
  <pre><code>   [Route("api/workers")]
      public IEnumerable&lt;object&gt; GetWorkers([FromRoute] string idEnterprise,int idDTO)
      {
          //lstDummyFields = _context.Dtos.Include("DtoFields").
             //Where(n=&gt;n.idDto==idDTO).select(n=&gt;n.DtoFields.name).ToList();
  
          //The property will look like this, the selected dto could have different properties(dynamic) but always call the same as the entity name fields
          List&lt;string&gt; lstDummyFields = new List&lt;string&gt;
          {
              "idWorker",
              "first_name",
              "last_name",
              "birthday",
              "adress"
          };
  
          dynamic dto = new ExpandoObject() as IDictionary&lt;string,object&gt;;
          foreach (var p in lstDummyProperty)
          {
              dto.Add(p, null);
          }
  
  
          return _context.workers.Where(n=&gt;n.IdEnterprise==idEnterprise).select.(new { ???? }) .ToList();
      }
  </code></pre>
  
  <p>I dont know how to implement the select clause.Could be related to this post but its sligtly different.</p>
  
  <p><a href="https://stackoverflow.com/a/34726946/2642777">https://stackoverflow.com/a/34726946/2642777</a></p>
  
  <p>I'm close to the answer or im going the wrong way? Could throw some help to solve this please.</p>