Explorar el Código

feat: 动态表达式 SqlFunc 支持,增加删除自定义过滤器缓存

许俊杰 hace 1 año
padre
commit
21609c490a

+ 11 - 0
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarFilter.cs

@@ -32,6 +32,17 @@ public static class SqlSugarFilter
         _cache.Remove($"db:{dbConfigId}:orgList:{userId}");
     }
 
+    /// <summary>
+    /// 删除自定义过滤器缓存
+    /// </summary>
+    /// <param name="userId"></param>
+    /// <param name="dbConfigId"></param>
+    public static void DeleteCustomCache(long userId, string dbConfigId)
+    {
+        // 删除自定义缓存——过滤器
+        _cache.Remove($"db:{dbConfigId}:custom:{userId}");
+    }
+
     /// <summary>
     /// 配置用户机构集合过滤器
     /// </summary>

+ 6 - 0
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<DbConnectionOptions>("DbConnection", true);
         dbOptions.ConnectionConfigs.ForEach(SetDbConfig);

+ 20 - 0
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarTypeProvider.cs

@@ -0,0 +1,20 @@
+using System.Linq.Dynamic.Core.CustomTypeProviders;
+
+namespace Admin.NET.Core;
+
+/// <summary>
+/// 扩展支持 SqlFunc,不支持 Subqueryable
+/// </summary>
+public class SqlSugarTypeProvider : DefaultDynamicLinqCustomTypeProvider
+{
+    public SqlSugarTypeProvider( bool cacheCustomTypes = true) : base(ParsingConfig.Default, cacheCustomTypes)
+    {
+    }
+
+    public override HashSet<Type> GetCustomTypes()
+    {
+        var customTypes = base.GetCustomTypes();
+        customTypes.Add(typeof(SqlFunc));
+        return customTypes;
+    }
+}