This is possible nowadays, but indeed passing just the name is not enough if you use different context types. I'm using .net core 2.2 and had the exact same issue. My code now is now like this:
I create a InMemoryDatabaseRoot object like this in class level
//using Microsoft.EntityFrameworkCore.Storage;
private static readonly InMemoryDatabaseRoot InMemoryDatabaseRoot = new InMemoryDatabaseRoot();
When I add the db contextes I pass the root instance
services.AddDbContext<MyContext>(options =>
{
options.UseInMemoryDatabase("MyContext", InMemoryDatabaseRoot);
options.UseInternalServiceProvider(serviceProvider);
});
services.AddDbContext<MySecondContext>(options =>
{
options.UseInMemoryDatabase("MyContext", InMemoryDatabaseRoot);
options.UseInternalServiceProvider(serviceProvider);
});
I found it in a discussion here: https://github.com/aspnet/EntityFrameworkCore/issues/9613#issuecomment-430722420
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…