内存数据库中的独立EF7 [英] Separate In Memory Databases EF7

查看:61
本文介绍了内存数据库中的独立EF7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以创建内存数据库中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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆