Separate In Memory Databases EF7

entity-framework-core xunit

Question

Is there any way to create a separate (isolated) instance of an EF7 In Memory Database? I am using the In Memory Database in Entity Framework 7 in my unit tests written in xUnit. I would like to be able to run the tests in parallel but this isn't really possible since it seems like the same in memory database is used for all the tests. What I would like is for each test to have its on isolated in memory database that isn't shared with the other tests that run in parallel.

Popular Answer

In EF Core you can pass a db name for InMemory db context.

Something like

var builder = new DbContextOptionsBuilder();
builder.UseInMemoryDatabase($"database{Guid.NewGuid()}");


Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why