-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some documentation for MySqlBatch.
Signed-off-by: Bradley Grainger <[email protected]>
- Loading branch information
Showing
4 changed files
with
133 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
date: 2019-06-23 | ||
menu: | ||
main: | ||
parent: api | ||
title: MySqlBatch | ||
weight: 10 | ||
--- | ||
|
||
# MySqlBatch | ||
|
||
`MySqlBatch` implements the new [ADO.NET batching API](https://github.com/dotnet/corefx/issues/35135). | ||
**It is currently experimental** and may change in the future. | ||
|
||
When using MariaDB (10.2 or later), the commands will be sent in a single batch, reducing network | ||
round-trip time. With other MySQL Servers, this may be no more efficient than executing the commands | ||
individually. | ||
|
||
## Example Code | ||
|
||
```csharp | ||
using (var connection = new MySqlConnection("...connection string...")) | ||
{ | ||
await connection.OpenAsync(); | ||
using (var batch = new MySqlBatch(connection) | ||
{ | ||
BatchCommands = | ||
{ | ||
new MySqlBatchCommand("INSERT INTO departments(name) VALUES(@name);") | ||
{ | ||
Parameters = | ||
{ | ||
new MySqlParameter("@name", "Sales"), | ||
}, | ||
}, | ||
new MySqlBatchCommand("SET @dept_id = last_insert_id()"), | ||
new MySqlBatchCommand("INSERT INTO employees(name, department_id) VALUES(@name, @dept_id);") | ||
{ | ||
Parameters = | ||
{ | ||
new MySqlParameter("@name", "Jim Halpert"), | ||
}, | ||
}, | ||
new MySqlBatchCommand("INSERT INTO employees(name, department_id) VALUES(@name, @dept_id);") | ||
{ | ||
Parameters = | ||
{ | ||
new MySqlParameter("@name", "Dwight Schrute"), | ||
}, | ||
}, | ||
}, | ||
}) | ||
{ | ||
await batch.ExecuteNonQueryAsync(); | ||
} | ||
} | ||
``` | ||
|
||
## API Reference | ||
|
||
### Constructors | ||
`public MySqlBatch()` | ||
|
||
Parameterless constructor. | ||
*** | ||
`public MySqlBatch(MySqlConnection connection)` | ||
|
||
Constructor that accepts a `MySqlConnection` and sets the `Connection` property. | ||
|
||
### Properties | ||
|
||
`public MySqlBatchCommandCollection BatchCommands { get; }` | ||
|
||
The collection of commands that will be executed in the batch. | ||
|
||
### Methods | ||
|
||
`public void ExecuteNonQuery();` | ||
`public Task ExecuteNonQueryAsync();` | ||
|
||
Executes all the commands in the batch, returning nothing. | ||
*** | ||
|
||
`public object ExecuteScalar();` | ||
`public Task<object> ExecuteScalarAsync();` | ||
|
||
Executes all the commands in the batch, returning the value from the first column in the first row of the first resultset. | ||
*** | ||
|
||
`public MySqlDataReader ExecuteReader();` | ||
`public Task<DbDataReader> ExecuteReaderAsync();` | ||
|
||
Executes all the commands in the batch, return a `DbDataReader` that can iterate over the result sets. If multiple | ||
resultsets are returned, use `DbDataReader.NextResult` (or `NextResultAsync`) to access them. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ menu: | |
main: | ||
parent: api | ||
title: MySqlDataReader | ||
weight: 30 | ||
weight: 40 | ||
--- | ||
|
||
MySqlDataReader | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ menu: | |
main: | ||
parent: api | ||
title: MySqlTransaction | ||
weight: 40 | ||
weight: 50 | ||
--- | ||
|
||
MySqlTransaction | ||
|