I am using (evaluating :)) Subsonic ActiveRecord mode for accessing sqLite. Need transaction to work. Regular stuff... Of ocurse!
Following snippet explains the desired logic. I couldn't find the right example in docs.
using (TransactionScope ts = new TransactionScope())
{
using (SharedD开发者_如何学运维bConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
{
// insert data in table 1 with primary key column. Save the id returned for later use.
// insert data in table 2 with a foreign key column. Use the Id generated in table 1.
// ts.commit here
}
}
Please advise. Thanks
http://www.sqlite.org/c3ref/last_insert_rowid.html
Here is what I was looking for.
using (var ts = new TransactionScope())
{
using (SharedDbConnectionScope scope = new SharedDbConnectionScope())
{
try
{
document.Save();
documentsDatum.DocumentId = document.Id;
documentsDatum.Save();
ts.Complete();
}
catch (Exception ex )
{
throw new Exception("trx failed " + ex.Message, ex);
}
}
}
精彩评论