From ef9d326131104ba7b5b30e880aecf480f487bb80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E4=BF=8A=E6=9D=B0?= Date: Sat, 23 Nov 2024 11:42:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8A=A8=E6=80=81=E8=A1=A8=E8=BE=BE?= =?UTF-8?q?=E5=BC=8F=20SqlFunc=20=E6=94=AF=E6=8C=81=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=88=A0=E9=99=A4=E8=87=AA=E5=AE=9A=E4=B9=89=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E5=99=A8=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin.NET.Core/SqlSugar/SqlSugarFilter.cs | 11 ++++++++++ .../Admin.NET.Core/SqlSugar/SqlSugarSetup.cs | 6 ++++++ .../SqlSugar/SqlSugarTypeProvider.cs | 20 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarTypeProvider.cs diff --git a/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarFilter.cs b/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarFilter.cs index 6e393a26..002e7482 100644 --- a/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarFilter.cs +++ b/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarFilter.cs @@ -32,6 +32,17 @@ public static class SqlSugarFilter _cache.Remove($"db:{dbConfigId}:orgList:{userId}"); } + /// + /// 删除自定义过滤器缓存 + /// + /// + /// + public static void DeleteCustomCache(long userId, string dbConfigId) + { + // 删除自定义缓存——过滤器 + _cache.Remove($"db:{dbConfigId}:custom:{userId}"); + } + /// /// 配置用户机构集合过滤器 /// diff --git a/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs b/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs index 45e666dd..a69e3cbf 100644 --- a/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs +++ b/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs @@ -30,6 +30,12 @@ public static class SqlSugarSetup { return YitIdHelper.NextId(); }; + // 动态表达式 SqlFunc 支持,https://www.donet5.com/Home/Doc?typeId=2569 + StaticConfig.DynamicExpressionParserType = typeof(DynamicExpressionParser); + StaticConfig.DynamicExpressionParsingConfig = new ParsingConfig + { + CustomTypeProvider = new SqlSugarTypeProvider() + }; var dbOptions = App.GetConfig("DbConnection", true); dbOptions.ConnectionConfigs.ForEach(SetDbConfig); diff --git a/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarTypeProvider.cs b/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarTypeProvider.cs new file mode 100644 index 00000000..3c1b0f96 --- /dev/null +++ b/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarTypeProvider.cs @@ -0,0 +1,20 @@ +using System.Linq.Dynamic.Core.CustomTypeProviders; + +namespace Admin.NET.Core; + +/// +/// 扩展支持 SqlFunc,不支持 Subqueryable +/// +public class SqlSugarTypeProvider : DefaultDynamicLinqCustomTypeProvider +{ + public SqlSugarTypeProvider( bool cacheCustomTypes = true) : base(ParsingConfig.Default, cacheCustomTypes) + { + } + + public override HashSet GetCustomTypes() + { + var customTypes = base.GetCustomTypes(); + customTypes.Add(typeof(SqlFunc)); + return customTypes; + } +} \ No newline at end of file