/// <summary> /// 生成查询过滤。 /// </summary> /// <param name="queryFilter">查询过来器实例。</param> /// <param name="parameters">查询参数</param> /// <returns></returns> public String GenerateFilter <TEntity>(QueryFilter queryFilter, DynamicParameters parameters) { if (queryFilter != null) { SingleQueryFilter sqf = queryFilter as SingleQueryFilter; if (sqf != null) { return(this.GenerateSingleFilter <TEntity>(sqf, parameters)); } CombinedQueryFilter cqf = queryFilter as CombinedQueryFilter; if (cqf != null) { return(GenerateCombinedFilter <TEntity>(cqf, parameters)); } } return(null); }
private string GenerateCombinedFilter <TEntity>(CombinedQueryFilter queryFilter, DynamicParameters parameters) { string spliter = queryFilter.Clause == BooleanClause.Or ? " OR " : " AND "; string left = this.GenerateFilter <TEntity>(queryFilter.Filter1, parameters); string right = this.GenerateFilter <TEntity>(queryFilter.Filter2, parameters); if (!right.IsNullOrWhiteSpace()) { if (left.IsNullOrWhiteSpace()) { return(right); } else { return($"({left}) {spliter} ({right})"); } } else { return(left.IfNullOrWhiteSpace(String.Empty)); } }