mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 23:13:40 +08:00
sqlsugar动态查询
This commit is contained in:
parent
a6c79bea7c
commit
38fee56701
@ -181,6 +181,17 @@ namespace Infrastructure
|
|||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ISugarQueryable<T> GenerateFilter<T>(this ISugarQueryable<T> query, string parametername, string filterjson)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(filterjson))
|
||||||
|
{
|
||||||
|
var filterGroup = JsonHelper.Instance.Deserialize<FilterGroup>(filterjson);
|
||||||
|
query = GenerateFilter(query, parametername, filterGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 转换FilterGroup为Lambda表达式
|
/// 转换FilterGroup为Lambda表达式
|
||||||
|
@ -3,6 +3,8 @@ using System.Linq;
|
|||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using OpenAuth.Repository.Domain;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
namespace OpenAuth.Repository.Test
|
namespace OpenAuth.Repository.Test
|
||||||
{
|
{
|
||||||
@ -11,7 +13,7 @@ namespace OpenAuth.Repository.Test
|
|||||||
[Test]
|
[Test]
|
||||||
public void GenerateFilter()
|
public void GenerateFilter()
|
||||||
{
|
{
|
||||||
var dbcontext = _autofacServiceProvider.GetService<OpenAuthDBContext>();
|
var sugarClient = _autofacServiceProvider.GetService<ISqlSugarClient>();
|
||||||
var json = @"
|
var json = @"
|
||||||
{
|
{
|
||||||
""Operation"": ""and"",
|
""Operation"": ""and"",
|
||||||
@ -50,8 +52,8 @@ namespace OpenAuth.Repository.Test
|
|||||||
}
|
}
|
||||||
";
|
";
|
||||||
|
|
||||||
var query = dbcontext.Users.GenerateFilter("c",json);
|
var query = sugarClient.Queryable<User>().GenerateFilter("c",json);
|
||||||
Console.WriteLine(query.Expression.ToString());
|
Console.WriteLine(query.ToSqlString());
|
||||||
|
|
||||||
Console.WriteLine(JsonHelper.Instance.Serialize(query.ToList()));
|
Console.WriteLine(JsonHelper.Instance.Serialize(query.ToList()));
|
||||||
}
|
}
|
||||||
@ -84,10 +86,10 @@ namespace OpenAuth.Repository.Test
|
|||||||
sub
|
sub
|
||||||
};
|
};
|
||||||
|
|
||||||
var dbcontext = _autofacServiceProvider.GetService<OpenAuthDBContext>();
|
var sugarClient = _autofacServiceProvider.GetService<ISqlSugarClient>();
|
||||||
|
|
||||||
var query = dbcontext.Users.GenerateFilter("c",JsonHelper.Instance.Serialize(filterGroup));
|
var query = sugarClient.Queryable<User>().GenerateFilter("c",filterGroup);
|
||||||
Console.WriteLine(query.Expression.ToString());
|
Console.WriteLine(query.ToSqlString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user