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