Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there an automatic way to generate a rollback script when inserting data with LINQ2SQL?
    primarykey
    data
    text
    <p>Let's assume we have a bunch of LINQ2SQL <code>InsertOnSubmit</code> statements against a given <code>DataContext</code>. If the <code>SubmitChanges</code> call is successful, is there any way to automatically generate a list of SQL commands (or even LINQ2SQL statements) that could <strong>undo</strong> everything that was submitted at a later time? It's like executing a rollback even though everything worked as expected.</p> <p>Note: The destination database will either be Oracle or SQL Server, so if there is specific functionality for both databases that will achieve this, I'm happy to use that as well.</p> <p><strong>Clarification:</strong> I do not want the "rollback" to happen automatically as soon as the inserts have succesfully completed. I want to have the ability to "undo" the INSERT statements via DELETE (or some other means) up to 24 hours (for example) after the original program finished inserting data. We can ignore any possible referential integrity issues that may come up.</p> <p>Assume a Table A with two columns: <code>Id</code> (autogenerated unique id) and <code>Value</code> (string)</p> <p>If the LINQ2SQL code performs two inserts</p> <pre><code> INSERT INTO Table A VALUES('a') // Creates new row with Id = 1 INSERT INTO Table A VALUES('z') // Creates new row with Id = 2 &lt;&lt; time passes&gt;&gt; </code></pre> <p>At some point later I would want to be able "undo" this by executing</p> <pre><code> DELETE FROM A Where Id = 1 DELETE FROM A Where Id = 2 </code></pre> <p>or something similar. I want to be able to generate the <code>DELETE</code> statements to match the <code>INSERT</code> ones. Or use some functionality that would let me capture a transaction and perform a rollback later.</p> <p>We cannot just 'reset the database' to a certain point in time either as other changes not initiated by our program could have taken place since.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload