Is it possible to have an InMemory database (ASP.NET Core) that is shared across multiple DbContexts? It seems that each DbContext type keeps its own database, even when the same database name is specified in UseInMemoryDatabase.
The same name is enough. If your instances of DbContext do not 'see' the same in memory DB, it seems they use ones with different names. Make sure your DbContext is created once for the same name.
EF Core 2.0
even re-uses in memory databases with the same name:
In-memory databases must be named
The global unnamed in-memory database has been removed and instead all in-memory databases must be named. For example:
optionsBuilder.UseInMemoryDatabase("MyDatabase");
This creates/uses a database with the name “MyDatabaseâ€. If
UseInMemoryDatabase
is called again with the same name, then the same in-memory database will be used, allowing it to be shared by multiple context instances.