AutoIncrement within Transactions fails

I am facing a weird issue.

I have a simple Product table, with an ID that is an int, auto increment. (SQLServer)
When I try .Save or Insert for this entity WITHIN a transaction this always fails with

{System.InvalidOperationException: ExecuteReader requires the command to have a transaction when the connection   assigned to the command is in a pending local transaction.  The Transaction property of the command has not been initialized.

I am using follow code: (some code left away)

using (var db = DbConnectionFactory.OpenDbConnection())
using (var transaction = db.BeginTransaction(IsolationLevel.ReadCommitted))
{
  try
  {
     var saved = db.Save(product);
     transaction.Commit();
  }
  catch (Exception e)
  {
      transaction.Rollback();
  }
}

What am I doing wrong? If I remove the transaction, this code is working.

You should be using OpenTransaction in OrmLite.

1 Like

:grimacing: :see_no_evil:
Thanks!