This is a migrated thread and some comments may be shown as answers.

Transaction Management

1 Answer 66 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Hasan Oz
Top achievements
Rank 1
Hasan Oz asked on 25 Aug 2010, 11:46 AM
Hi,
I have relational tables. After add a record to one table before scope.Commit() I must get the record Id.
For consistency after some add, delete or update operations I can Commit or Roolback  all operations.
Is there a way for this transaction management ?
Can I get  autoincrement Id before commit?
Is rollback after commit is possible?
Thanks.

1 Answer, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 25 Aug 2010, 12:24 PM
Hi Hasan,

I think what you need is a call to Flush() .

The Flush method will give you almost "Commit behavior". For instance:

1) Flush() will apply the changes on the database level, but not commit them at the database level
2) After Flush() you can still do a Rollback()
3) After Flush() the Id of a new persistent instance will be available in the instance.

Pseudo code:

// Scope level transaction starts
Transaction.Begin()

// Do something to create a new persistent object - in this example an Order
Order order = new Order();
order.IssueDate = DateTime.Now

// Flush the changes recorded in the ObjectScope (since scope level transaction start) to the database level.
Transaction.Flush()

// Now you can read the Id of the newly flushed Order instance.
int orderId = order.Id;

// And you can still do a rollback (or commit in non-error cases)
Transaction.Rollback();

So Flush() is like a "soft-Commit" at the database level.

So what is the drawback of using Flush()?

At the database level you will have a running transaction until you either do a Commit or a Rollback..  Usually that is not a problem with short lived scope transactions..

Regards

Henrik


Tags
Development (API, general questions)
Asked by
Hasan Oz
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
Share this question
or