Skip to content

Commit 132ee0d

Browse files
committed
doco with rollback
1 parent 78bba1c commit 132ee0d

6 files changed

Lines changed: 116 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# With Rollback
2+
3+
Multiple actions a targeted to the same database and changes are rolled back instead of being committed.
4+
5+
Characteristics:
6+
7+
* Better performance that the standard API.
8+
* If a test fails, it is not possible to look at the current database state.
9+
10+
If a test has failed, to debug the database state, temporarily switch back to the standard API.
11+
12+
13+
## Usage
14+
15+
snippet: WithRollback
16+
17+
18+
## EntityFramework Usage
19+
20+
snippet: EfWithRollback

pages/with-rollback.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!--
2+
GENERATED FILE - DO NOT EDIT
3+
This file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets).
4+
Source File: /pages/mdsource/with-rollback.source.md
5+
To change this file edit the source file and then run MarkdownSnippets.
6+
-->
7+
# With Rollback
8+
9+
Multiple actions a targeted to the same database and changes are rolled back instead of being committed.
10+
11+
Characteristics:
12+
13+
* Better performance that the standard API.
14+
* If a test fails, it is not possible to look at the current database state.
15+
16+
If a test has failed, to debug the database state, temporarily switch back to the standard API.
17+
18+
19+
## Usage
20+
21+
<!-- snippet: WithRollback -->
22+
```cs
23+
var sqlInstance = new SqlInstance(
24+
name: "theInstanceName",
25+
buildTemplate: TestDbBuilder.CreateTable
26+
);
27+
28+
using (var sqlDatabase = await sqlInstance.BuildWithRollback())
29+
{
30+
var sqlConnection = sqlDatabase.Connection;
31+
//Use the SqlConnection
32+
}
33+
```
34+
<sup>[snippet source](/src/LocalDb.Tests/Snippets/WithRollback.cs#L8-L19)</sup>
35+
<!-- endsnippet -->
36+
37+
38+
## EntityFramework Usage
39+
40+
<!-- snippet: EfWithRollback -->
41+
```cs
42+
var sqlInstance = new SqlInstance<TheDbContext>(
43+
constructInstance: builder => new TheDbContext(builder.Options));
44+
45+
using (var sqlDatabase = await sqlInstance.BuildWithRollback())
46+
{
47+
var sqlConnection = sqlDatabase.Connection;
48+
var dbContext = sqlDatabase.Context;
49+
//Use the SqlConnection or TheDbContext
50+
}
51+
```
52+
<sup>[snippet source](/src/EfLocalDb.Tests/Snippets/WithRollback.cs#L8-L18)</sup>
53+
<!-- endsnippet -->

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Provides a wrapper around [SqlLocalDB](https://docs.microsoft.com/en-us/sql/data
1616
* [Raw SqlConnection Usage](/pages/raw-usage.md)
1717
* [EntityFramework Usage](/pages/ef-usage.md)
1818
* [EntityFramework Migrations](/pages/efmigrations.md)
19+
* [With Rollback Usage](/pages/with-rollback.md)
1920
* [Directory and name resolution](/pages/directory-and-name-resolution.md)
2021
* [Sql Management Studio](/pages/sql-management-studio.md)
2122
* [Logging](/pages/logging.md)

readme.source.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Provides a wrapper around [SqlLocalDB](https://docs.microsoft.com/en-us/sql/data
1010
* [Raw SqlConnection Usage](/pages/raw-usage.md)
1111
* [EntityFramework Usage](/pages/ef-usage.md)
1212
* [EntityFramework Migrations](/pages/efmigrations.md)
13+
* [With Rollback Usage](/pages/with-rollback.md)
1314
* [Directory and name resolution](/pages/directory-and-name-resolution.md)
1415
* [Sql Management Studio](/pages/sql-management-studio.md)
1516
* [Logging](/pages/logging.md)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Threading.Tasks;
2+
using EfLocalDb;
3+
4+
class WithRollback
5+
{
6+
async Task Usage()
7+
{
8+
#region EfWithRollback
9+
var sqlInstance = new SqlInstance<TheDbContext>(
10+
constructInstance: builder => new TheDbContext(builder.Options));
11+
12+
using (var sqlDatabase = await sqlInstance.BuildWithRollback())
13+
{
14+
var sqlConnection = sqlDatabase.Connection;
15+
var dbContext = sqlDatabase.Context;
16+
//Use the SqlConnection or TheDbContext
17+
}
18+
#endregion
19+
}
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Threading.Tasks;
2+
using LocalDb;
3+
4+
class WithRollback
5+
{
6+
async Task Usage()
7+
{
8+
#region WithRollback
9+
var sqlInstance = new SqlInstance(
10+
name: "theInstanceName",
11+
buildTemplate: TestDbBuilder.CreateTable
12+
);
13+
14+
using (var sqlDatabase = await sqlInstance.BuildWithRollback())
15+
{
16+
var sqlConnection = sqlDatabase.Connection;
17+
//Use the SqlConnection
18+
}
19+
#endregion
20+
}
21+
}

0 commit comments

Comments
 (0)