aboutsummaryrefslogtreecommitdiffstats
path: root/src/IOL.Helpers/QueryableHelpers.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/IOL.Helpers/QueryableHelpers.cs')
-rw-r--r--src/IOL.Helpers/QueryableHelpers.cs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/IOL.Helpers/QueryableHelpers.cs b/src/IOL.Helpers/QueryableHelpers.cs
new file mode 100644
index 0000000..00f422b
--- /dev/null
+++ b/src/IOL.Helpers/QueryableHelpers.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Linq;
+using System.Linq.Expressions;
+
+namespace IOL.Helpers;
+
+public static class QueryableHelpers
+{
+ public static IQueryable<T> ConditionalWhere<T>(
+ this IQueryable<T> source,
+ Func<bool> condition,
+ Expression<Func<T, bool>> predicate
+ ) {
+ return condition() ? source.Where(predicate) : source;
+ }
+
+ public static IQueryable<T> ConditionalWhere<T>(
+ this IQueryable<T> source,
+ bool condition,
+ Expression<Func<T, bool>> predicate
+ ) {
+ return condition ? source.Where(predicate) : source;
+ }
+}