public static Dictionary <string, object>?GetArguments <TResult>(this FilteringConfiguration.Filter filter) { if (filter.Operator == FilteringConfiguration.FilterComparisonOperator.IsNotNull || filter.Operator == FilteringConfiguration.FilterComparisonOperator.IsNull) { return(new Dictionary <string, object>()); } if (filter.Operator == FilteringConfiguration.FilterComparisonOperator.In) { var fieldName = filter.GetFieldName <TResult>() !; var filterValues = GetFilterValuesList <TResult>(filter); if (filterValues == null) { return(null); } var paramNames = GetInOperatorParamNames(fieldName, filterValues); return(paramNames.Zip(filterValues, (n, v) => new { n, v }) .ToDictionary(x => x.n, x => x.v)); } if (filter.Operator == FilteringConfiguration.FilterComparisonOperator.Between) { var fieldName = filter.GetFieldName <TResult>() !; var filterValues = GetFilterValuesList <TResult>(filter); if (filterValues == null || filterValues.Count != 2) { return(null); } var paramNames = GetBetweenOperatorParameterNames <TResult>(filter, fieldName); return(paramNames.Zip(filterValues, (n, v) => new { n, v }) .ToDictionary(x => x.n, x => x.v)); } var paramName = filter.GetParameterName <TResult>(); var value = GetFilterValue <TResult>(filter); var args = new Dictionary <string, object> { { paramName, value } }; return(args); }
private static string GetFilterSql(FilteringConfiguration.Filter filter) { var sqlOperator = filter.GetSqlComparisonOperator(); var fieldName = filter.GetFieldName <TResult>() !; var paramName = filter.GetParameterName <TResult>(); if (filter.Operator == FilteringConfiguration.FilterComparisonOperator.DateEquals) { return($"CAST({fieldName} AS DATE) {sqlOperator} CAST({paramName} AS DATE)"); } return($"{fieldName} {sqlOperator} {paramName}".Trim()); }
public static string?GetParameterName <TResult>(this FilteringConfiguration.Filter filter) { var fieldName = filter.GetFieldName <TResult>() !; switch (filter.Operator) { case FilteringConfiguration.FilterComparisonOperator.IsNotNull: case FilteringConfiguration.FilterComparisonOperator.IsNull: return(""); case FilteringConfiguration.FilterComparisonOperator.In: return(GetInOperatorParameterName <TResult>(filter, fieldName)); case FilteringConfiguration.FilterComparisonOperator.Between: return(GetBetweenOperatorParameterExpression <TResult>(filter, fieldName)); default: return($"@Filtering_{fieldName}"); } }