浏览代码

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

zuohuaijun 2 年之前
父节点
当前提交
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;
         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 };
+    }
 }
 }