内存数据库中的独立EF7

编程入门 行业动态 更新时间:2024-10-28 09:17:28
本文介绍了内存数据库中的独立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

本文发布于:2023-11-14 03:20:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586072.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   内存   独立

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!