commit 977b3bba95c6181be63a5729447f5a548353fe91
parent 3400be98ae7ae670646c7e501ca2f592fcbb4903
Author: novickii.sergei.nure@gmail.com <novickii.sergei.nure@gmail.com>
Date: Mon, 1 Jul 2024 22:16:55 +0300
Fixed an error when creating a predicate from an empty filtering model. Now, if the filtering model is empty, the predicate will return all the elements of the collection.
Diffstat:
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/QueryExpressionBuilder/Attributes.cs b/QueryExpressionBuilder/Attributes.cs
@@ -4,8 +4,7 @@
/// Attribute to filtration strings
/// </summary>
public class String
- {
-
+ {
/// <summary>
/// Filtration func StartWith
/// </summary>
diff --git a/QueryExpressionBuilder/ExpressionBuilder.cs b/QueryExpressionBuilder/ExpressionBuilder.cs
@@ -90,6 +90,18 @@ namespace QueryExpressionBuilder
prop.GetCustomAttribute<GreaterOrEqualAttribute>() != null || prop.GetCustomAttribute<StartWithAttribute>() != null ||
prop.GetCustomAttribute<ContainsAttribute>() != null || prop.GetCustomAttribute<EqualsAttribute>() != null).ToArray();
+ // Проверка, пустые ли все свойства query
+ bool allPropertiesNull = true;
+ for (int i = 0; i < T_pr_props.Length; i++)
+ {
+ if (T_pr_props[i].GetValue(query) != null)
+ {
+ allPropertiesNull = false;
+ break;
+ }
+ }
+ if (allPropertiesNull) return _ => true;
+
//Проходимся по всем параметрам класса БД
foreach (var p in typeof(TDB).GetProperties())
{