diff --git a/src/Extensions/DataServices/BootstrapBlazor.DataAccess.FreeSql/BootstrapBlazor.DataAccess.FreeSql.csproj b/src/Extensions/DataServices/BootstrapBlazor.DataAccess.FreeSql/BootstrapBlazor.DataAccess.FreeSql.csproj index 5fdd6d070..da8b86ee5 100644 --- a/src/Extensions/DataServices/BootstrapBlazor.DataAccess.FreeSql/BootstrapBlazor.DataAccess.FreeSql.csproj +++ b/src/Extensions/DataServices/BootstrapBlazor.DataAccess.FreeSql/BootstrapBlazor.DataAccess.FreeSql.csproj @@ -1,7 +1,7 @@ - 8.1.1 + 8.1.2 diff --git a/src/Extensions/DataServices/BootstrapBlazor.DataAccess.FreeSql/FreeSqlExtensions.cs b/src/Extensions/DataServices/BootstrapBlazor.DataAccess.FreeSql/FreeSqlExtensions.cs index 54c4d3b8d..51ef9d728 100644 --- a/src/Extensions/DataServices/BootstrapBlazor.DataAccess.FreeSql/FreeSqlExtensions.cs +++ b/src/Extensions/DataServices/BootstrapBlazor.DataAccess.FreeSql/FreeSqlExtensions.cs @@ -13,7 +13,7 @@ namespace BootstrapBlazor.DataAccess.FreeSql; public static class FreeSqlExtensions { /// - /// + /// QueryPageOptions 转化为 FreeSql ORM DynamicFilterInfo 类型扩展方法 /// /// /// @@ -51,41 +51,26 @@ public static class FreeSqlExtensions return ret; } - private static DynamicFilterInfo ToDynamicFilter(this IFilterAction filter) + /// + /// IFilterAction 转化为 DynamicFilterInfo 扩展方法 + /// + /// + /// + public static DynamicFilterInfo ToDynamicFilter(this IFilterAction filter) { - var actions = filter.GetFilterConditions(); - var item = new DynamicFilterInfo(); - - if (actions.Filters != null) - { - // TableFilter 最多仅两个条件 - if (actions.Filters.Count == 2) - { - item.Logic = actions.FilterLogic.ToDynamicFilterLogic(); - item.Filters = actions.Filters.Select(i => new DynamicFilterInfo() - { - Field = i.FieldKey, - Value = i.FieldValue, - Operator = i.FilterAction.ToDynamicFilterOperator() - }).ToList(); - } - else - { - var c = actions.Filters.First(); - item.Field = c.FieldKey; - item.Value = c.FieldValue; - item.Operator = c.FilterAction.ToDynamicFilterOperator(); - } - } - else - { - item.Field = actions.FieldKey; - item.Value = actions.FieldValue; - item.Operator = actions.FilterAction.ToDynamicFilterOperator(); - } - return item; + var filterKeyValueAction = filter.GetFilterConditions(); + return filterKeyValueAction.ParseDynamicFilterInfo(); } + private static DynamicFilterInfo ParseDynamicFilterInfo(this FilterKeyValueAction filterKeyValueAction) => new() + { + Operator = filterKeyValueAction.FilterAction.ToDynamicFilterOperator(), + Logic = filterKeyValueAction.FilterLogic.ToDynamicFilterLogic(), + Field = filterKeyValueAction.FieldKey, + Value = filterKeyValueAction.FieldValue, + Filters = filterKeyValueAction.Filters?.Select(i => i.ParseDynamicFilterInfo()).ToList() + }; + private static DynamicFilterLogic ToDynamicFilterLogic(this FilterLogic logic) => logic switch { FilterLogic.And => DynamicFilterLogic.And,