title: Copying a row from one table to another using LINQ and C#
body: <p>I have two tables that are pretty much exact clones of one another (identical columns, just different columns set as primary keys). Basically the second table is just for keeping a history of the first table. What I need to do is, when a user updates a record in table 1 I need to insert the original copy of that record into table 2.</p>
  
  <p>I am using a LinqDataSource object and utilizing the <code>LinqDataSource_Updating(object sender, LinqDataSourceUpdateEventArgs e)</code> event so I have access to <code>e.OriginalObject</code> and  that will be perfect for inserting the original row in table 2. My problem is that I don't want to have to set every property manually because there are about 50 of them, so I want to use Reflection but am not sure how to properly go about it.</p>
  
  <p>Consider the following code:</p>
  
  <pre><code>INSTRUMENT_DATA_SHEET _original = (INSTRUMENT_DATA_SHEET)e.OriginalObject;
  INSTRUMENT_DATA_SHEET_HISTORY _history = new INSTRUMENT_DATA_SHEET_HISTORY();
  </code></pre>
  
  <p>How can I go about copying all of the <code>_original</code>'s property values to <code>_history</code>'s? I have tried using the solution from <a href="https://stackoverflow.com/questions/930433/apply-properties-values-from-one-object-to-another-of-the-same-type-automaticall">this question</a>, however it isn't working for me. It throws the error:</p>
  
  <p><code>Property DATE has an incompatible type in E_and_I.INSTRUMENT_DATA_SHEET_HISTORY</code></p>
  
  <p>My guess is that it's because the <code>DATE</code> column is part of the primary key in table 2, but not table 1. As I said, the only difference between the two tables are the primary keys. Here they are for your reference:</p>
  
  <p><img src="https://i.stack.imgur.com/aDpsi.png" alt="Primary Keys"></p>