Skip to content

Execute multiple SQL statements in a single round trip to database.

License

Notifications You must be signed in to change notification settings

adimiko/TransactionContext

Repository files navigation

TransactionContext (Proof of concept)

TransactionContext is designed to execute statements changing state (also call to stored procedures) in a single transaction and a single request to database (collects SQL statements without instant execution).

It can be an alternative for Entity Framework Core and TransactionScope in .NET.

ITransactionContext

transactionContext.Add("INSERT INTO Customers (CustomerId) VALUES (@CustomerId)", new { CustomerId = Guid.NewGuid() });
transactionContext.Add("INSERT INTO Orders (OrderId) VALUES (@OrderId)", new { OrderId = Guid.NewGuid() });

transactionContext.Commit() open connection, create transaction and execute sql statments in a single database request.

await transactionContext.Commit();

IDbConnectionFactory

Package also includes a database connection factory.

using var connection = dbConnectionFactory.Create()

Databases

Postgres

Add package

dotnet add package TransactionContext.Postgres

Register dependencies

services.AddTransactionContext(x => x.UsePostgres(connectionString));

Microsoft SQL Server (preview)

Add package

dotnet add package TransactionContext.SqlServer

Register dependencies

services.AddTransactionContext(x => x.UseSqlServer(connectionString));

MySql (also MariaDb)

Add package

dotnet add package TransactionContext.MySql

Register dependencies

services.AddTransactionContext(x => x.UseMySql(connectionString));

About

Execute multiple SQL statements in a single round trip to database.

Topics

Resources

License

Stars

Watchers

Forks