-
Notifications
You must be signed in to change notification settings - Fork 147
Transactions
Chris Skardon edited this page Jul 21, 2015
·
7 revisions
The current pre-release (1.1.0-Tx#) contains a Transactions implementation.
Important Note for Async Users
To use Transactions with async, you need to be compiling agains .NET 4.5.1 or higher, this is because the TransactionScope
only started supporting async with 4.5.1
Use Neo4jClient
as you would normally, to execute in a transaction, wrap your calls in a TransactionScope
Use the Complete()
method on the TransactionScope
to commit the transaction. The below code will create two nodes in the database.
using(var scope = new TransactionScope())
{
client.Cypher.Create("(n:Tx {Value:'Test'})").ExecuteWithoutResults();
client.Cypher.Create("(n:Tx {Value:'Test2'})").ExecuteWithoutResults();
scope.Complete();
}
Rollback is as simple as just not calling Complete()
, the below code will not create anything in the database:
using(var scope = new TransactionScope())
{
client.Cypher.Create("(n:Tx {Value:'Test'})").ExecuteWithoutResults();
client.Cypher.Create("(n:Tx {Value:'Test2'})").ExecuteWithoutResults();
//No Complete() call, so rolling back
}