- 修复 SqlServer WithLock 子查询不生效的 bug;#1159

This commit is contained in:
2881099
2022-06-21 12:40:14 +08:00
parent 26115cfc93
commit aac99d6266
4 changed files with 292 additions and 184 deletions

View File

@ -2541,10 +2541,52 @@ WHERE (((name,no) in (('testname01','testname01')) OR not((a.""no"") LIKE '%test
public ts_dyfilter_enum01_status status { get; set; }
}
public enum ts_dyfilter_enum01_status { staring, stoped, finished }
[Fact]
public void WhereDynamicFilter2()
{
var fsql = g.sqlite;
var dyfilterJson = @"
{
""Logic"" : ""Or"",
""Filters"" :
[
{
""Field"" : ""RegCount FreeSql.Tests.Sqlite.DynamicFilterMyCustom, FreeSql.Tests.Provider.Sqlite.Data"",
""Operator"" : ""Custom"",
""Value"" : ""19""
},
{
""Field"" : ""name"",
""Operator"" : ""NotEndsWith"",
""Value"" : ""testname01""
}
]
}";
var dyfilter = JsonConvert.DeserializeObject<DynamicFilterInfo>(dyfilterJson);
var sql = fsql.Select<ts_dyfilter_enum01>().WhereDynamicFilter(dyfilter).ToSql();
}
}
class RegLog
{
public Guid tid { get; set; }
}
public class DynamicFilterMyCustom
{
[DynamicFilterCustom]
public static string RegCount(object sender, string value)
{
var count = int.Parse(value);
var select = sender as Select0Provider;
var sql = select._orm.Select<RegLog>().ToSql("count(1)");
return $"({sql}) > {count}";
}
[DynamicFilterCustom]
public static string MyRawSql(object sender, string value) => value;

View File

@ -1890,6 +1890,27 @@ INNER JOIN [TestTypeInfo] a__Type With(NoLock) ON a__Type.[Guid] = a.[Id]", sql2
Assert.Equal(@"SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime]
FROM [tb_topic22] a
INNER JOIN [TestTypeInfo] a__Type With(NoLock) ON a__Type.[Guid] = a.[Id]", sql2);
sql2 = orm.Select<Topic>()
.InnerJoin(a => a.Type.Guid == a.Id)
.WithLock(SqlServerLock.NoLock)
.ToSql();
Assert.Equal(@"SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime]
FROM [tb_topic22] a With(NoLock)
INNER JOIN [TestTypeInfo] a__Type With(NoLock) ON a__Type.[Guid] = a.[Id]", sql2);
sql2 = orm.Select<Topic>()
.InnerJoin(a => a.Type.Guid == a.Id)
.WithLock(SqlServerLock.NoLock)
.Where(a => orm.Select<TestTypeInfo>()
.WithLock(SqlServerLock.NoLock, null).Where(b => b.Guid == a.TypeGuid).Any())
.ToSql();
Assert.Equal(@"SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime]
FROM [tb_topic22] a With(NoLock)
INNER JOIN [TestTypeInfo] a__Type With(NoLock) ON a__Type.[Guid] = a.[Id]
WHERE (exists(SELECT TOP 1 1
FROM [TestTypeInfo] b With(NoLock)
WHERE (b.[Guid] = a.[TypeGuid])))", sql2);
}
[Fact]
public void ForUpdate()