Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is no option to specify the order of operations in a transaction as it is hard-coded as follows (from the documentation):</p> <blockquote> <p>The SQL statements are issued in the following order</p> <ul> <li>all entity insertions, in the same order the corresponding objects were saved using ISession.Save()</li> <li>all entity updates</li> <li>all collection deletions</li> <li>all collection element deletions, updates and insertions</li> <li>all collection insertions</li> <li>all entity deletions, in the same order the corresponding objects were deleted using ISession.Delete()</li> </ul> <p>(An exception is that objects using native ID generation are inserted when they are saved.)</p> </blockquote> <p>As such, can I challenge you to answer <em>why</em> you are adding a new entity with an existing identifier? An identifier is supposed to be unique to a specific "entity." If that entity is gone, so should be its identifier. </p> <p>Another option would be to do an update on that record instead of a delete/insert. This keeps the ID the same so there is no unique constraint violation (on the key at least) and you can change all the other data so that it's a "new" record.</p> <p>EDIT: So apparently I wasn't entirely paying attention to the question when I responded since this is a problem with a unique constraint on a non-primary-key column.</p> <p>I think you have two solutions to choose from:</p> <ol> <li>Call <code>Session.Flush()</code> after your delete which will execute all the changes to the session up to that point, after which you can continue with the rest (inserting your new object). This works inside of a transaction as well so you don't need to worry about atomicity.</li> <li>Create a <code>ReplacePage</code> function which updates the existing entity with new data but keeps the primary-key and the unique column the same.</li> </ol>
 

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