What’s wrong with the following code?
using (var transaction = session.BeginTransaction()) { session.Save(something); transaction .Commit(); }
Nothing if you are using MySQL connector 6.0, which has the following Dispose method on its MySqlTransaction class.
protected override void Dispose(bool disposing) { if ((((this.conn != null) && (this.conn.State == ConnectionState.Open)) || this.conn.SoftClosed) && this.open) { this.Rollback(); } base.Dispose(disposing); }
But if you are using 5.0.9, check out this code (which is actually from the underlying DbTransaction object).
public void Dispose() { this.Dispose(true); } protected virtual void Dispose(bool disposing) { }
Where’s the rollback? Missing. Just wait till your next transaction block.
Looks like it was fixed in 5.1. Srijak and Dellanoce figured this out, but I sniped it from them before they could post. I was standing over their shoulder :)