diff --git a/Infrastructure/DynamicLinq.cs b/Infrastructure/DynamicLinq.cs index 0e0761da..5dbd361e 100644 --- a/Infrastructure/DynamicLinq.cs +++ b/Infrastructure/DynamicLinq.cs @@ -181,6 +181,17 @@ namespace Infrastructure return query; } + + public static ISugarQueryable GenerateFilter(this ISugarQueryable query, string parametername, string filterjson) + { + if (!string.IsNullOrEmpty(filterjson)) + { + var filterGroup = JsonHelper.Instance.Deserialize(filterjson); + query = GenerateFilter(query, parametername, filterGroup); + } + + return query; + } /// /// 转换FilterGroup为Lambda表达式 diff --git a/OpenAuth.Repository/Test/TestSugarDynamicLinq.cs b/OpenAuth.Repository/Test/TestSugarDynamicLinq.cs index 4834d512..f29e0757 100644 --- a/OpenAuth.Repository/Test/TestSugarDynamicLinq.cs +++ b/OpenAuth.Repository/Test/TestSugarDynamicLinq.cs @@ -3,6 +3,8 @@ using System.Linq; using Infrastructure; using NUnit.Framework; using Microsoft.Extensions.DependencyInjection; +using OpenAuth.Repository.Domain; +using SqlSugar; namespace OpenAuth.Repository.Test { @@ -11,7 +13,7 @@ namespace OpenAuth.Repository.Test [Test] public void GenerateFilter() { - var dbcontext = _autofacServiceProvider.GetService(); + var sugarClient = _autofacServiceProvider.GetService(); var json = @" { ""Operation"": ""and"", @@ -50,8 +52,8 @@ namespace OpenAuth.Repository.Test } "; - var query = dbcontext.Users.GenerateFilter("c",json); - Console.WriteLine(query.Expression.ToString()); + var query = sugarClient.Queryable().GenerateFilter("c",json); + Console.WriteLine(query.ToSqlString()); Console.WriteLine(JsonHelper.Instance.Serialize(query.ToList())); } @@ -84,10 +86,10 @@ namespace OpenAuth.Repository.Test sub }; - var dbcontext = _autofacServiceProvider.GetService(); + var sugarClient = _autofacServiceProvider.GetService(); - var query = dbcontext.Users.GenerateFilter("c",JsonHelper.Instance.Serialize(filterGroup)); - Console.WriteLine(query.Expression.ToString()); + var query = sugarClient.Queryable().GenerateFilter("c",filterGroup); + Console.WriteLine(query.ToSqlString()); } } } \ No newline at end of file