Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions client-sdk-references/dotnet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* **WPF**: Windows desktop applications

**Current Limitations**:
* Blazor (web) platforms are not yet supported.

Check warning on line 50 in client-sdk-references/dotnet.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

client-sdk-references/dotnet.mdx#L50

Did you really mean 'Blazor'?

For more details, please refer to the package [README](https://github.com/powersync-ja/powersync-dotnet/tree/main?tab=readme-ov-file).

Expand Down Expand Up @@ -166,7 +166,7 @@

public class MyConnector : IPowerSyncBackendConnector
{
private readonly HttpClient _httpClient;

Check warning on line 169 in client-sdk-references/dotnet.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

client-sdk-references/dotnet.mdx#L169

Did you really mean 'readonly'?

Check warning on line 169 in client-sdk-references/dotnet.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

client-sdk-references/dotnet.mdx#L169

Did you really mean '_httpClient'?

// User credentials for the current session
public string UserId { get; private set; }
Expand Down Expand Up @@ -297,6 +297,38 @@
);
```

### 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<NonQueryResult> 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"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can omit the first parameter, and make the first ? be uuid()? Or is that not prefered?

[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.
Expand Down