mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 修复 WhereDynamicFilter 在 System.Text.Json 下的问题 #371;
This commit is contained in:
parent
4447500d57
commit
f93e0f1b54
@ -7,8 +7,12 @@ using Newtonsoft.Json.Linq;
|
|||||||
using System;
|
using System;
|
||||||
using System.Data.Odbc;
|
using System.Data.Odbc;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
|
using System.Data.SQLite;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -40,8 +44,23 @@ namespace base_entity
|
|||||||
|
|
||||||
static AsyncLocal<IUnitOfWork> _asyncUow = new AsyncLocal<IUnitOfWork>();
|
static AsyncLocal<IUnitOfWork> _asyncUow = new AsyncLocal<IUnitOfWork>();
|
||||||
|
|
||||||
|
public class TestEnumCls
|
||||||
|
{
|
||||||
|
public CollationTypeEnum val { get; set; } = CollationTypeEnum.Binary;
|
||||||
|
}
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
// var result2 = Newtonsoft.Json.JsonConvert.DeserializeObject<TestEnumCls>(@"
|
||||||
|
//{
|
||||||
|
// ""val"": ""Binary""
|
||||||
|
//}");
|
||||||
|
// var result1 = System.Text.Json.JsonSerializer.Deserialize<TestEnumCls>(@"
|
||||||
|
//{
|
||||||
|
// ""val"": ""Binary""
|
||||||
|
//}");
|
||||||
|
|
||||||
|
|
||||||
#region 初始化 IFreeSql
|
#region 初始化 IFreeSql
|
||||||
var fsql = new FreeSql.FreeSqlBuilder()
|
var fsql = new FreeSql.FreeSqlBuilder()
|
||||||
.UseAutoSyncStructure(true)
|
.UseAutoSyncStructure(true)
|
||||||
@ -90,7 +109,7 @@ namespace base_entity
|
|||||||
new Products { title = "product-4" }.Save();
|
new Products { title = "product-4" }.Save();
|
||||||
new Products { title = "product-5" }.Save();
|
new Products { title = "product-5" }.Save();
|
||||||
|
|
||||||
Products.Select.WhereDynamicFilter(JsonConvert.DeserializeObject<DynamicFilterInfo>(@"
|
var wdy1 = JsonConvert.DeserializeObject<DynamicFilterInfo>(@"
|
||||||
{
|
{
|
||||||
""Logic"" : ""Or"",
|
""Logic"" : ""Or"",
|
||||||
""Filters"" :
|
""Filters"" :
|
||||||
@ -125,7 +144,52 @@ namespace base_entity
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
")).ToList();
|
");
|
||||||
|
var config = new JsonSerializerOptions()
|
||||||
|
{
|
||||||
|
PropertyNamingPolicy = null,
|
||||||
|
AllowTrailingCommas = true,
|
||||||
|
IgnoreNullValues = true,
|
||||||
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||||
|
Converters = { new JsonStringEnumConverter() }
|
||||||
|
};
|
||||||
|
var wdy2 = System.Text.Json.JsonSerializer.Deserialize<DynamicFilterInfo>(@"
|
||||||
|
{
|
||||||
|
""Logic"" : 1,
|
||||||
|
""Filters"" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
""Field"" : ""title"",
|
||||||
|
""Operator"" : 8,
|
||||||
|
""Value"" : ""product-1"",
|
||||||
|
""Filters"" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
""Field"" : ""title"",
|
||||||
|
""Operator"" : 0,
|
||||||
|
""Value"" : ""product-1111""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""Field"" : ""title"",
|
||||||
|
""Operator"" : 8,
|
||||||
|
""Value"" : ""product-2""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""Field"" : ""title"",
|
||||||
|
""Operator"" : 8,
|
||||||
|
""Value"" : ""product-3""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""Field"" : ""title"",
|
||||||
|
""Operator"" : 8,
|
||||||
|
""Value"" : ""product-4""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
", config);
|
||||||
|
Products.Select.WhereDynamicFilter(wdy2).ToList();
|
||||||
|
|
||||||
var items1 = Products.Select.Limit(10).OrderByDescending(a => a.CreateTime).ToList();
|
var items1 = Products.Select.Limit(10).OrderByDescending(a => a.CreateTime).ToList();
|
||||||
var items2 = fsql.Select<Products>().Limit(10).OrderByDescending(a => a.CreateTime).ToList();
|
var items2 = fsql.Select<Products>().Limit(10).OrderByDescending(a => a.CreateTime).ToList();
|
||||||
|
@ -486,14 +486,5 @@
|
|||||||
<param name="that"></param>
|
<param name="that"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
|
||||||
<summary>
|
|
||||||
批量注入 Repository,可以参考代码自行调整
|
|
||||||
</summary>
|
|
||||||
<param name="services"></param>
|
|
||||||
<param name="globalDataFilter"></param>
|
|
||||||
<param name="assemblies"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
@ -175,6 +175,12 @@ namespace FreeSql.Tests
|
|||||||
|
|
||||||
.Page(1, 10).ToSql("Id");
|
.Page(1, 10).ToSql("Id");
|
||||||
|
|
||||||
|
var sqlextMax1 = g.mysql.Select<EdiItem>()
|
||||||
|
.GroupBy(a => a.Id)
|
||||||
|
.ToSql(a => new
|
||||||
|
{
|
||||||
|
Id = a.Key, EdiId = SqlExt.Max(a.Key).Over().ToValue()
|
||||||
|
});
|
||||||
|
|
||||||
var sqlextGroupConcat = g.mysql.Select<Edi, EdiItem>()
|
var sqlextGroupConcat = g.mysql.Select<Edi, EdiItem>()
|
||||||
.InnerJoin((a, b) => b.Id == a.Id)
|
.InnerJoin((a, b) => b.Id == a.Id)
|
||||||
|
@ -1086,12 +1086,12 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
|
|
||||||
switch (fi.Operator)
|
switch (fi.Operator)
|
||||||
{
|
{
|
||||||
case DynamicFilterOperator.Contains: exp = Expression.Call(exp, MethodStringContains, Expression.Constant(fi.Value)); break;
|
case DynamicFilterOperator.Contains: exp = Expression.Call(exp, MethodStringContains, Expression.Constant(Utils.GetDataReaderValue(exp.Type, fi.Value), exp.Type)); break;
|
||||||
case DynamicFilterOperator.StartsWith: exp = Expression.Call(exp, MethodStringStartsWith, Expression.Constant(fi.Value)); break;
|
case DynamicFilterOperator.StartsWith: exp = Expression.Call(exp, MethodStringStartsWith, Expression.Constant(Utils.GetDataReaderValue(exp.Type, fi.Value), exp.Type)); break;
|
||||||
case DynamicFilterOperator.EndsWith: exp = Expression.Call(exp, MethodStringEndsWith, Expression.Constant(fi.Value)); break;
|
case DynamicFilterOperator.EndsWith: exp = Expression.Call(exp, MethodStringEndsWith, Expression.Constant(Utils.GetDataReaderValue(exp.Type, fi.Value), exp.Type)); break;
|
||||||
case DynamicFilterOperator.NotContains: exp = Expression.Not(Expression.Call(exp, MethodStringContains, Expression.Constant(fi.Value))); break;
|
case DynamicFilterOperator.NotContains: exp = Expression.Not(Expression.Call(exp, MethodStringContains, Expression.Constant(Utils.GetDataReaderValue(exp.Type, fi.Value), exp.Type))); break;
|
||||||
case DynamicFilterOperator.NotStartsWith: exp = Expression.Not(Expression.Call(exp, MethodStringStartsWith, Expression.Constant(fi.Value))); break;
|
case DynamicFilterOperator.NotStartsWith: exp = Expression.Not(Expression.Call(exp, MethodStringStartsWith, Expression.Constant(Utils.GetDataReaderValue(exp.Type, fi.Value), exp.Type))); break;
|
||||||
case DynamicFilterOperator.NotEndsWith: exp = Expression.Not(Expression.Call(exp, MethodStringEndsWith, Expression.Constant(fi.Value))); break;
|
case DynamicFilterOperator.NotEndsWith: exp = Expression.Not(Expression.Call(exp, MethodStringEndsWith, Expression.Constant(Utils.GetDataReaderValue(exp.Type, fi.Value), exp.Type))); break;
|
||||||
|
|
||||||
case DynamicFilterOperator.Eq:
|
case DynamicFilterOperator.Eq:
|
||||||
case DynamicFilterOperator.Equals:
|
case DynamicFilterOperator.Equals:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user