title: Entity class to Datatable
body: <p>I'm trying to make a generic class to save log</p>
  
  <p>Here we use entity framework so imagine we have table
  mng_users(string usr_name, int usr_id)
  creating the respective class for itentity)</p>
  
  <p>is there a way to implement the toDataTable method converting the entity into a datatable(not a list, having 1 row only) so i can do something like this:</p>
  
  <p>having mng_users1 and mng_users2 as mng_users entity class(both with the same id but diff name)</p>
  
  <p>call method "savelog(mng_users1, mng_users2);"
  and do the following code:</p>
  
  <pre><code>    private DataTable toDataTable(Object T)
      {
          DataTable vDataTable = new DataTable();
  
          //AddColums here
          //AddRow with the respective values here
  
          return vDataTable;
      }
  
      public void savelog(Object newObject, Object oldObject)
      {
  
          DataTable newvalue, oldvalue;
  
          newvalue = toDataTable(newObject);
          oldvalue = toDataTable(oldObject);
  
         string FieldNames = string.Empty, FieldValuesFrom = string.Empty, FieldValuesTo = string.Empty;
         foreach (DataColumn item in newvalue.Columns)
                  {
                      if (newvalue.Rows[0][item].ToString() != oldvalue.Rows[0][item].ToString())
                      {
                          FieldNames += (FieldNames.Length &gt; 0 ? " | " : string.Empty) + item.ColumnName;
                          FieldValuesFrom += (FieldValuesFrom.Length &gt; 0 ? " | " : string.Empty) + newvalue.Rows[0][item].ToString();
                          FieldValuesTo += (FieldValuesTo.Length &gt; 0 ? " | " : string.Empty) + oldvalue.Rows[0][item].ToString();
                      }
  
                  }
          // Save log to sql code here
      }
  </code></pre>