diff --git a/client-sdk-references/dotnet.mdx b/client-sdk-references/dotnet.mdx index 15510d05..516b238f 100644 --- a/client-sdk-references/dotnet.mdx +++ b/client-sdk-references/dotnet.mdx @@ -297,6 +297,38 @@ await db.Execute( ); ``` +### Batch execution + +Use `ExecuteBatch` for bulk inserts or updates. This method executes the same SQL statement multiple times with different parameter sets, reusing the compiled statement for significantly better performance. + +```cs +Task ExecuteBatch(string query, object?[][]? parameters = null) +``` + +**When to use**: Use `ExecuteBatch` instead of multiple `Execute` calls when inserting or updating many rows at once. The performance improvement is substantial for larger datasets: + +| Entries | Individual inserts (ms) | Batch insert (ms) | +|---------|-------------------------|-------------------| +| 10 | 2 | 2 | +| 1,000 | 110 | 10 | +| 10,000 | 842 | 91 | +| 100,000 | 10,801 | 830 | + +**Example**: + +```cs +// Insert multiple assets in a single batch operation +var sql = "INSERT INTO assets (id, description, make) VALUES (?, ?, ?)"; +object?[][] parameters = [ + [Guid.NewGuid().ToString(), "Asset 1", "Make A"], + [Guid.NewGuid().ToString(), "Asset 2", "Make B"], + [Guid.NewGuid().ToString(), "Asset 3", "Make C"] +]; + +var result = await db.ExecuteBatch(sql, parameters); +Console.WriteLine($"Rows affected: {result.RowsAffected}"); +``` + ## Access PowerSync connection status information Use [SyncStatus](https://github.com/powersync-ja/powersync-dotnet/blob/main/PowerSync/PowerSync.Common/DB/Crud/SyncStatus.cs) and access [RunListener](https://github.com/powersync-ja/powersync-dotnet/blob/main/PowerSync/PowerSync.Common/Client/PowerSyncDatabase.cs) to listen for status changes to your PowerSync instance.