private DbCommand getSelectCommand(int pageSize, int pageNo, string fields, Dictionary <string, string> queryParams, string where, string orderBy, string groupBy) { string connectionName = _schema.ConnectionName; string selectSql; // tableNames = new List<string>(); DbCommand cmd = null; switch (_schema.SelectCommand.CommandType) { case CommandType.TableDirect: if (pageNo > 1 || pageSize > 1) { cmd = getPagingSpCommand(_schema.SelectCommand.CommandText, pageSize, pageNo, fields, where, orderBy, groupBy); } if (cmd == null) { selectSql = XSqlBuilder.BuildTableSql(_schema.SelectCommand.CommandText, pageSize, pageNo, fields, where, orderBy, groupBy); cmd = dbAdmin.getSqlStringCommand(selectSql); } else { _schema.IsPagingByParams = true; } break; case CommandType.Text: selectSql = _schema.SelectCommand.CommandText; SqlParse xSql = new SqlParse(selectSql); cmd = dbAdmin.getSqlStringCommand(selectSql); // paramNames = xSql.GetParamNames(); break; case CommandType.StoredProcedure: selectSql = _schema.SelectCommand.CommandText; cmd = dbAdmin.GetStoredProcCommandWithSourceColumns(selectSql, fields.Split(',')); break; } if (_schema.SelectCommand != null && _schema.SelectCommand.QueryParams != null) { foreach (ParameterSchema ps in _schema.SelectCommand.QueryParams) { if (string.IsNullOrEmpty(ps.Id)) { continue; } string name = ps.Id; object value = ps.DefaultValue; if (queryParams != null && queryParams.ContainsKey(name)) { value = queryParams[name]; } //if (name.Equals(DataSourceConst.PagingPageNo, StringComparison.OrdinalIgnoreCase)) // value = pageNo; //if (name.Equals(DataSourceConst.PagingPageSize, StringComparison.OrdinalIgnoreCase)) // value = pageSize; if (cmd.Parameters.Contains(name)) { dbAdmin.Database.SetParameterValue(cmd, name, value); } else if (ps.Direction == ParameterDirection.Input) { dbAdmin.addInParameter(cmd, name, ps.DataType, value); } else { dbAdmin.AddOutParameter(cmd, name, ps.DataType, ps.DataSize); } } } return(cmd); }