我有一个带有“SelfRef”表的数据库。SelfRef 有两个字段:
Id (guid, PK, not null)
SelfRefId (guid, nullable)
Run Code Online (Sandbox Code Playgroud)
有一个外键约束将 SelfRefId 字段映射回 Id 字段。
我有一个引用数据库的 EntityFrameworkCore 项目。我正在运行以下测试:
我发现第 2 步经常导致死锁。我不明白为什么应该这样做。
我在下面展示了我的代码,但我怀疑这个问题是特定于这段代码的:
public class TestSelfRefDeadlock
{
private async Task CreateSelfRef_ThenDelete_Deletes() {
var sr = new SelfRef
{
Id = Guid.NewGuid(),
Name = "SR"
};
var factory = new SelfRefDbFactory();
using (var db = factory.Create()) {
db.Add(sr);
await db.SaveChangesAsync(); // EDIT: Changing this to db.SaveChanges() appears to fix the problem, at least in this test scenario. …
Run Code Online (Sandbox Code Playgroud) 我有一个 Azure 数据库的连接字符串。我希望 SSMS 中有一个地方可以插入该字符串并连接到它。或者,如果有一种方法可以使用 T-SQL 查询来做到这一点,那就更好了。