|
| 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 --> |
0 commit comments