是否有任何方法可以创建内存数据库中EF7的单独(隔离)实例?我在以xUnit编写的单元测试中使用Entity Framework 7中的In Memory Database。我希望能够并行运行测试,但这实际上是不可能的,因为所有测试似乎都使用相同的内存数据库。我想要的是让每个测试都隔离在内存数据库中,并且不与并行运行的其他测试共享。
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.
推荐答案在EF Core中,您可以为InMemory数据库上下文传递数据库名称。
In EF Core you can pass a db name for InMemory db context.
类似
var builder = new DbContextOptionsBuilder(); builder.UseInMemoryDatabase($"database{Guid.NewGuid()}");更多推荐
内存数据库中的独立EF7
发布评论