Skip to content

Commit f2d395b

Browse files
GKotfiscincuranet
andauthored
Emphasize that new db is created for sqlite and in-memory (#4800)
* emphasize that new db is created * Highlight also 'deleted' word --------- Co-authored-by: Jiri Cincura <[email protected]>
1 parent 6e738dc commit f2d395b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

entity-framework/core/testing/testing-without-the-database.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ The full sample code can be viewed [here](https://github.com/dotnet/EntityFramew
5555

5656
SQLite can easily be configured as the EF Core provider for your test suite instead of your production database system (e.g. SQL Server); consult the [SQLite provider docs](xref:core/providers/sqlite/index) for details. However, it's usually a good idea to use SQLite's [in-memory database](https://sqlite.org/inmemorydb.html) feature when testing, since it provides easy isolation between tests, and does not require dealing with actual SQLite files.
5757

58-
To use in-memory SQLite, it's important to understand that a new database is created whenever a low-level connection is opened, and that it's deleted when that connection is closed. In normal usage, EF Core's `DbContext` opens and closes database connections as needed - every time a query is executed - to avoid keeping connection for unnecessarily long times. However, with in-memory SQLite this would lead to resetting the database every time; so as a workaround, we open the connection before passing it to EF Core, and arrange for it to be closed only when the test completes:
58+
To use in-memory SQLite, it's important to understand that a **new database is created** whenever a low-level connection is opened, and that it's **deleted** when that connection is closed. In normal usage, EF Core's `DbContext` opens and closes database connections as needed - every time a query is executed - to avoid keeping connection for unnecessarily long times. However, with in-memory SQLite this would lead to resetting the database every time; so as a workaround, we open the connection before passing it to EF Core, and arrange for it to be closed only when the test completes:
5959

6060
[!code-csharp[Main](../../../samples/core/Testing/TestingWithoutTheDatabase/SqliteInMemoryBloggingControllerTest.cs?name=ConstructorAndDispose)]
6161

0 commit comments

Comments
 (0)