public override string OutputSqlString(ISqlBuilder builder, ParameterCollection output) { if (_fields == null || _fields.Count == 0) { Fields.AddRang(accessor.MetaInfo.GetPropertyNames().Select(x => SqlExpression.Field(x))); } var topExpressions = top > 0 ? builder.Constant(top) : string.Empty; var fieldExpressions = Fields.OutputSqlString(builder, output); var tableExpression = builder.BuildTableName(accessor.MetaInfo.Name); var conditionExpressions = _where != null?_where.OutputSqlString(builder, output) : string.Empty; var groupbyExpression = _groups != null && _groups.Count > 0 ? _groups.OutputSqlString(builder, output) : string.Empty; var havingExpression = _groups != null && _groups.Count > 0 && _having != null?_having.OutputSqlString(builder, output) : string.Empty; var orderbyExpression = _orders != null && _orders.Count > 0 ? string.Join(",", _orders.Select(x => string.Concat(x.Key.OutputSqlString(builder, output), " ", x.Value ? "DESC" : "ASC"))) : string.Empty; if (startIndex < 0) { return(builder.QueryFormat( topExpressions, //top(10) fieldExpressions, //id,name,... tableExpression, //tableName conditionExpressions, //where id>1 and... groupbyExpression, //group by name.... havingExpression, //having count(name)>1 ... orderbyExpression, //order id distinct ? Options | SqlOptions.Distinct : Options )); } else { return(builder.QueryFormat( fieldExpressions, //id,name,... tableExpression, //tableName conditionExpressions, //where id>1 and... groupbyExpression, //group by name.... havingExpression, //having count(name)>1 ... orderbyExpression, //order id startIndex, rowCount, distinct ? Options | SqlOptions.Distinct : Options )); } }