/// <inheritdoc /> public IEnumerable <TViewData> Execute <TDataFilter>(IDataFilter <TDataFilter, TData> filter, IDbConnection connection) where TDataFilter : IDataFilter <TDataFilter, TData> { if (!_compiled) { Compile(); } var parameters = new Dictionary <string, object>(); var transaction = default(IDbTransaction); var buffered = true; int?commandTimeout = null; var filterPredicate = _predicateFactory.GetPredicate <TDataFilter, TData>(filter); var filterSql = _predicateQueryBuilderFactory .GetQueryBuilder(filterPredicate, this) .GetSql(filterPredicate, parameters); var dynamicParameters = new DynamicParameters(); foreach (var parameter in parameters) { dynamicParameters.Add(parameter.Key, parameter.Value); } return(connection.Query <TViewData>($"{_query} WHERE {filterSql}", dynamicParameters, transaction, buffered, commandTimeout, CommandType.Text)); }
private string GetSql(IPredicateGroup predicateGroup, IDictionary <string, object> parameters) { var separator = predicateGroup.Operator == GroupOperator.And ? " AND " : " OR "; var predicateSqlStatements = predicateGroup.Predicates .Select(predicate => _predicateQueryBuilderFactory.GetQueryBuilder(predicate, _sqlBuilder).GetSql(predicate, parameters)) .Where(sql => !string.IsNullOrEmpty(sql)) .ToArray(); return(predicateSqlStatements.Length == 0 ? _sqlBuilder.Dialect.EmptyExpression : $"({string.Join(separator, predicateSqlStatements)})"); }