- 增加 ISelect.ForUpdate 排他更新锁(根据数据库类型的规则,见代码注释);

- 完善 SqlServer WithLock 功能,组合多种使用 | 枚举相联;
This commit is contained in:
28810
2019-12-14 11:43:17 +08:00
parent 655d19153b
commit 15c3ab7297
32 changed files with 470 additions and 170 deletions

View File

@ -1598,5 +1598,21 @@ namespace FreeSql.Tests.MySqlConnector
Assert.Equal(5, g.mysql.Select<ToUpd3Pk>().Count());
Assert.Equal(5, g.mysql.Select<ToUpd3Pk>().Where(a => a.name.StartsWith("nick")).Count());
}
[Fact]
public void ForUpdate()
{
var orm = g.mysql;
orm.Transaction(() =>
{
var sql = orm.Select<ToUpd1Pk>().ForUpdate().Limit(1).ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.`id`, a.`name` FROM `ToUpd1Pk` a limit 0,1 for update", sql);
orm.Select<ToUpd1Pk>().ForUpdate().Limit(1).ToList();
sql = orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.`id`, a.`name` FROM `ToUpd1Pk` a limit 0,1 for update", sql);
orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToList();
});
}
}
}