Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separate In Memory Databases EF7

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.

like image 841
Abris Avatar asked Jan 21 '16 14:01

Abris


1 Answers

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

Something like

var builder = new DbContextOptionsBuilder();
builder.UseInMemoryDatabase($"database{Guid.NewGuid()}");
like image 140
Yuriy Granovskiy Avatar answered Oct 07 '22 12:10

Yuriy Granovskiy