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

This commit is contained in:
许俊杰 2024-11-23 11:42:42 +08:00
parent cf3e6d8a25
commit ef9d326131
3 changed files with 37 additions and 0 deletions

View File

@ -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>

View File

@ -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);

View File

@ -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;
}
}