title: Read and change @data in an object variable
body: <p>First, the scenario. I want to display some data with <code>DataTables</code>. For that, I created a generic service called <code>TableService</code> that receives some params and one of them is an <code>IQueryable&lt;T&gt;</code>.</p>
  <p><code>TableService</code> checks the values from the form, sorts the data, applies conditions and takes the record for a specific page. It returns an object with only the records to display.</p>
  <pre><code>public object GetRecords(string draw, string length, string start, string columnSort,
      string columnDirectrion, string search, IFormCollection form, IQueryable&lt;T&gt; data,
      Expression&lt;Func&lt;T, bool&gt;&gt; condition)
  {
      var drawValue = form.GetValueOrDefault(&quot;draw&quot;, draw);
      var lengthValue = form.GetValueOrDefault(&quot;length&quot;, length);
      var startValue = form.GetValueOrDefault(&quot;start&quot;, start);
      var sortColumn = columnSort ?? form[&quot;columns[&quot; + form[&quot;order[0][column]&quot;].FirstOrDefault() + 
                       &quot;][name]&quot;].FirstOrDefault();
      var sortColumnDirection = form.GetValueOrDefault(&quot;order[0][dir]&quot;, columnDirectrion);
      var searchValue = form.GetValueOrDefault(&quot;search[value]&quot;, search);
  
      int pageSize = !string.IsNullOrEmpty(length) ? Convert.ToInt32(lengthValue) : 10;
      int skip = !string.IsNullOrEmpty(start) ? Convert.ToInt32(startValue) : 0;
  
      if (!(string.IsNullOrEmpty(sortColumn) &amp;&amp; string.IsNullOrEmpty(sortColumnDirection)))
          data = data.OrderBy(sortColumn + &quot; &quot; + sortColumnDirection);
  
      if (!string.IsNullOrEmpty(searchValue))
          data = data.Where(condition);
  
      var recordsTotal = data.Count();
  
      var rtn = data.Skip(skip).Take(pageSize);
      var jsonData = new { draw = drawValue, recordsFiltered = recordsTotal, 
                     recordsTotal = recordsTotal, data = rtn };
      return jsonData;
  }
  </code></pre>
  <p>The function is really working and the result is ok. An example in the image below.</p>
  <p><a href="https://i.stack.imgur.com/kowAr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kowAr.png" alt="enter image description here" /></a></p>
  <p>Where is my problem then? Some fields are IDs and I want to replace the IDs with the real value. So, for that, I want to read the output of this function and change the <code>@data</code>. My idea was:</p>
  <ul>
  <li>read the <code>@data</code> and convert them to the original type (in the image <em>AzureCost</em>)</li>
  <li>create a new <code>List</code> with the data from the original type and the real values instead of the IDs</li>
  <li>replace <code>@data</code> with my new list of values</li>
  </ul>
  <p>How can I do that?</p>