dotnet-dynamic-linq/PoweredSoft.DynamicLinq/Fluent/WhereBuilder/WhereBuilderBase.cs

62 lines
2.0 KiB
C#
Raw Normal View History

using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PoweredSoft.DynamicLinq.Fluent
{
2018-03-14 19:17:25 -04:00
public abstract partial class WhereBuilderBase
{
public bool IsNullCheckingEnabled { get; protected set; } = false;
2018-03-14 19:17:25 -04:00
public List<WhereBuilderCondition> Filters { get; protected set; } = new List<WhereBuilderCondition>();
2018-03-14 19:17:25 -04:00
public virtual WhereBuilderBase NullChecking(bool check = true)
{
IsNullCheckingEnabled = check;
return this;
}
2018-03-14 19:17:25 -04:00
public virtual WhereBuilderBase Compare(string path, ConditionOperators conditionOperators, object value,
QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField,
2018-03-06 20:43:49 -05:00
bool and = true, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
{
2018-03-14 19:17:25 -04:00
Filters.Add(new WhereBuilderCondition
{
And = and,
ConditionOperator = conditionOperators,
Path = path,
Value = value,
ConvertStrategy = convertStrategy,
2018-03-06 20:43:49 -05:00
CollectionHandling = collectionHandling,
StringComparisation = stringComparision
});
return this;
}
2018-03-14 19:17:25 -04:00
protected abstract WhereBuilderBase GetSubQueryBuilder();
2018-03-14 19:17:25 -04:00
public virtual WhereBuilderBase SubQuery(Action<WhereBuilderBase> subQuery, bool and = true)
{
// create query builder for same type.
var qb = GetSubQueryBuilder();
qb.NullChecking(IsNullCheckingEnabled);
// callback.
subQuery(qb);
// create a query part.
2018-03-14 19:17:25 -04:00
var part = new WhereBuilderCondition();
part.And = and;
2018-03-14 19:17:25 -04:00
part.Conditions = qb.Filters;
Filters.Add(part);
//return self.
return this;
2018-02-28 18:07:34 -05:00
}
}
}