Reputation: 906
I configured my ASP.NET Core 2.2 app using UseInMemoryDatabase() and it worked fine. Now I changed it to relational Sqlite in-memory.
Startup.cs
services.AddDbContext<ApplicationContext>(options => options.UseSqlite("Datasource=file::memory:?cache=shared"));
I use this Sqlite in-memory approach in unit tests and it work good. So decided I want to use the same in-memory Sqlite in my app (to test some things, later when app will be ready I'll create sqlite file on disk). The problem is when I starting my app. I receive erros like SqliteException: SQLite Error 1: 'no such table: USERS'
. I debug my repository class and I found that context has table Users.
So Sqlite in-memory works fine in unit tests but in real app throws error. Why is that? Thanks for any tips.
Upvotes: 3
Views: 2856
Reputation: 156
Create and apply migrations to your in-memory SQLite database. You'll have to apply them every time the app starts, since the database only exists in memory until the application exits.
Upvotes: 1