Просмотр исходного кода

!983 【轻量级 PR】:导航+子表过滤 创建一个扩展函数,默认是Class不支持Where和WhereIF
Merge pull request !983 from Mr先生/N/A

zuohuaijun 2 лет назад
Родитель
Сommit
0f88147fd3
1 измененных файлов с 29 добавлено и 0 удалено
  1. 29 0
      Admin.NET/Admin.NET.Core/Extension/RepositoryExtension.cs

+ 29 - 0
Admin.NET/Admin.NET.Core/Extension/RepositoryExtension.cs

@@ -361,4 +361,33 @@ public static class RepositoryExtension
     {
         return ignore ? queryable.ClearFilter<ITenantIdFilter>() : queryable;
     }
+
+    /// <summary>
+    /// 导航+子表过滤 创建一个扩展函数,默认是Class不支持Where
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    /// <param name="thisValue"></param>
+    /// <param name="whereExpression"></param>
+    /// <returns></returns>
+    public static List<T> Where<T>(this T thisValue, Func<T, bool> whereExpression) where T : class, new()
+    {
+        return new List<T>() { thisValue };
+    }
+
+    /// <summary>
+    /// 导航+子表过滤 创建一个扩展函数,默认是Class不支持WhereIF
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    /// <param name="thisValue"></param>
+    /// <param name="isWhere"></param>
+    /// <param name="whereExpression"></param>
+    /// <returns></returns>
+    public static List<T> WhereIF<T>(this T thisValue, bool isWhere, Func<T, bool> whereExpression) where T : class, new()
+    {
+        if (!isWhere)
+        {
+            return new List<T>() { thisValue };
+        }
+        return new List<T>() { thisValue };
+    }
 }