mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- 优化 WhereDynamicFilter;
This commit is contained in:
parent
6ab2f3922f
commit
53669da86e
@ -208,6 +208,11 @@ namespace base_entity
|
|||||||
""Operator"" : ""Range"",
|
""Operator"" : ""Range"",
|
||||||
""Value"" : [""101"",""202""]
|
""Value"" : [""101"",""202""]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
""Field"" : ""testint"",
|
||||||
|
""Operator"" : ""contains"",
|
||||||
|
""Value"" : ""123""
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
");
|
");
|
||||||
|
@ -2424,6 +2424,47 @@ FROM ""D_District"" a
|
|||||||
LEFT JOIN ""D_District"" a__Parent ON a__Parent.""Code"" = a.""ParentCode""
|
LEFT JOIN ""D_District"" a__Parent ON a__Parent.""Code"" = a.""ParentCode""
|
||||||
WHERE ((not((a.""Code"") LIKE '%val1%') AND not((a.""Name"") LIKE 'val2%') OR not((a.""Name"") LIKE '%val3') OR a.""ParentCode"" <> 'val4' OR a__Parent.""Code"" = 'val11' AND (a__Parent.""Name"") LIKE '%val22%' OR a__Parent.""Name"" = 'val33' OR a__Parent.""ParentCode"" = 'val44'))
|
WHERE ((not((a.""Code"") LIKE '%val1%') AND not((a.""Name"") LIKE 'val2%') OR not((a.""Name"") LIKE '%val3') OR a.""ParentCode"" <> 'val4' OR a__Parent.""Code"" = 'val11' AND (a__Parent.""Name"") LIKE '%val22%' OR a__Parent.""Name"" = 'val33' OR a__Parent.""ParentCode"" = 'val44'))
|
||||||
ORDER BY a__Parent.""Name""", sql);
|
ORDER BY a__Parent.""Name""", sql);
|
||||||
|
|
||||||
|
sql = fsql.Select<ts_dyfilter_enum01>().WhereDynamicFilter(JsonConvert.DeserializeObject<DynamicFilterInfo>(@"
|
||||||
|
{
|
||||||
|
""Logic"" : ""Or"",
|
||||||
|
""Filters"" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
""Field"" : ""name"",
|
||||||
|
""Operator"" : ""NotEndsWith"",
|
||||||
|
""Value"" : ""testname01""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""Field"" : ""no"",
|
||||||
|
""Operator"" : ""NotEndsWith"",
|
||||||
|
""Value"" : ""testname01""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""Field"" : ""id"",
|
||||||
|
""Operator"" : ""NotEndsWith"",
|
||||||
|
""Value"" : ""testname01""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""Field"" : ""status"",
|
||||||
|
""Operator"" : ""eq"",
|
||||||
|
""Value"" : ""finished""
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
")).ToSql();
|
||||||
|
Assert.Equal(@"SELECT a.""id"", a.""name"", a.""no"", a.""status""
|
||||||
|
FROM ""ts_dyfilter_enum01"" a
|
||||||
|
WHERE ((not((a.""name"") LIKE '%testname01') OR not((a.""no"") LIKE '%testname01') OR not((a.""id"") LIKE '%testname01') OR a.""status"" = 2))", sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ts_dyfilter_enum01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
public int no { get; set; }
|
||||||
|
public ts_dyfilter_enum01_status status { get; set; }
|
||||||
|
}
|
||||||
|
public enum ts_dyfilter_enum01_status { staring, stoped, finished }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -525,6 +525,17 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
{
|
{
|
||||||
Expression exp = ConvertStringPropertyToExpression(fi.Field);
|
Expression exp = ConvertStringPropertyToExpression(fi.Field);
|
||||||
switch (fi.Operator)
|
switch (fi.Operator)
|
||||||
|
{
|
||||||
|
case DynamicFilterOperator.Contains:
|
||||||
|
case DynamicFilterOperator.StartsWith:
|
||||||
|
case DynamicFilterOperator.EndsWith:
|
||||||
|
case DynamicFilterOperator.NotContains:
|
||||||
|
case DynamicFilterOperator.NotStartsWith:
|
||||||
|
case DynamicFilterOperator.NotEndsWith:
|
||||||
|
if (exp.Type != typeof(string)) exp = Expression.TypeAs(exp, typeof(string));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (fi.Operator)
|
||||||
{
|
{
|
||||||
case DynamicFilterOperator.Contains: exp = Expression.Call(exp, MethodStringContains, Expression.Constant(Utils.GetDataReaderValue(exp.Type, fi.Value?.ToString()), exp.Type)); break;
|
case DynamicFilterOperator.Contains: exp = Expression.Call(exp, MethodStringContains, Expression.Constant(Utils.GetDataReaderValue(exp.Type, fi.Value?.ToString()), exp.Type)); break;
|
||||||
case DynamicFilterOperator.StartsWith: exp = Expression.Call(exp, MethodStringStartsWith, Expression.Constant(Utils.GetDataReaderValue(exp.Type, fi.Value?.ToString()), exp.Type)); break;
|
case DynamicFilterOperator.StartsWith: exp = Expression.Call(exp, MethodStringStartsWith, Expression.Constant(Utils.GetDataReaderValue(exp.Type, fi.Value?.ToString()), exp.Type)); break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user