This example demonstrates transaction support in the GraphModel library, including commit, rollback, and data consistency.
- Beginning and managing transactions
- Committing successful operations
- Rolling back failed operations
- Ensuring data consistency across multiple operations
- Working with transactions in a banking scenario
using (var transaction = await graph.BeginTransactionAsync())
{
try
{
// Perform operations
await transaction.CreateNode(node);
await transaction.UpdateNode(node);
// Commit if successful
await transaction.CommitAsync();
}
catch
{
// Rollback on failure
await transaction.RollbackAsync();
throw;
}
}All operations within a transaction are isolated from other transactions until committed.
If an exception occurs and the transaction is not explicitly committed, it will be rolled back automatically when disposed.
Transactions can include multiple creates, updates, and deletes that all succeed or fail together.
The example simulates a simple banking system with:
- Account creation
- Money transfers between accounts
- Balance validation
- Transaction history
cd examples/Example3.TransactionManagement
dotnet runMake sure Neo4j is running and accessible at neo4j://localhost:7687.