/// <summary> /// Query using the specified <see cref="SoqlQuery"/> against the specified resource identifier. /// </summary> /// <typeparam name="TRow">The .NET class that represents the type of the underlying rows in the result set of this query.</typeparam> /// <param name="soqlQuery">A <see cref="SoqlQuery"/> to execute against the Resource.</param> /// <param name="resourceId">The identifier (4x4) for a resource on the Socrata host to target.</param> /// <returns>A collection of entities of type <typeparamref name="TRow"/>.</returns> /// <exception cref="System.ArgumentOutOfRangeException">Thrown if the specified <paramref name="resourceId"/> does not match the Socrata 4x4 pattern.</exception> /// <remarks> /// By default, Socrata will only return the first 1000 rows unless otherwise specified in SoQL using the Limit and Offset parameters. /// This method checks the specified SoqlQuery object for either the Limit or Offset parameter, and honors those parameters if present. /// If both Limit and Offset are not part of the SoqlQuery, this method attempts to retrieve all rows in the dataset across all pages. /// In other words, this method hides the fact that Socrata will only return 1000 rows at a time, unless explicity told not to via the SoqlQuery argument. /// </remarks> public IEnumerable <TRow> Query <TRow>(SoqlQuery soqlQuery, string resourceId) where TRow : class { if (FourByFour.IsNotValid(resourceId)) { throw new ArgumentOutOfRangeException("resourceId", "The provided resourceId is not a valid Socrata (4x4) resource identifier."); } //if the query explicitly asks for a limit/offset, honor the ask if (soqlQuery.LimitValue > 0 || soqlQuery.OffsetValue > 0) { var queryUri = SodaUri.ForQuery(Host, resourceId, soqlQuery); return(read <IEnumerable <TRow> >(queryUri)); } //otherwise, go nuts and get EVERYTHING else { List <TRow> allResults = new List <TRow>(); int offset = 0; soqlQuery = soqlQuery.Limit(SoqlQuery.MaximumLimit).Offset(offset); IEnumerable <TRow> offsetResults = read <IEnumerable <TRow> >(SodaUri.ForQuery(Host, resourceId, soqlQuery)); while (offsetResults.Any()) { allResults.AddRange(offsetResults); soqlQuery = soqlQuery.Offset(++offset * SoqlQuery.MaximumLimit); offsetResults = read <IEnumerable <TRow> >(SodaUri.ForQuery(Host, resourceId, soqlQuery)); } return(allResults); } }
/// <summary> /// Query this Resource using the specified <see cref="SoqlQuery"/>. /// </summary> /// <typeparam name="T">The .NET class that represents the type of the underlying rows in this resultset of this query.</typeparam> /// <param name="soqlQuery">A <see cref="SoqlQuery"/> to execute against this Resource.</param> /// <returns>A collection of entities of type <typeparamref name="T"/>.</returns> /// <remarks> /// By default, Socrata will only return the first 1000 rows unless otherwise specified in SoQL using the Limit and Offset parameters. /// This method checks the specified SoqlQuery object for either the Limit or Offset parameter, and honors those parameters if present. /// If both Limit and Offset are not part of the SoqlQuery, this method attempts to retrieve all rows in the dataset across all pages. /// In other words, this method hides the fact that Socrata will only return 1000 rows at a time, unless explicity told not to via the SoqlQuery argument. /// </remarks> public IEnumerable <T> Query <T>(SoqlQuery soqlQuery) where T : class { //if the query explicitly asks for a limit/offset, honor the ask if (soqlQuery.LimitValue > 0 || soqlQuery.OffsetValue > 0) { var queryUri = SodaUri.ForQuery(Host, Identifier, soqlQuery); return(Client.read <IEnumerable <T> >(queryUri)); } //otherwise, go nuts and get EVERYTHING else { List <T> allResults = new List <T>(); int offset = 0; IEnumerable <T> offsetResults = Client.read <IEnumerable <T> >(SodaUri.ForQuery(Host, Identifier, soqlQuery)); while (offsetResults.Any()) { allResults.AddRange(offsetResults); soqlQuery = soqlQuery.Offset(++offset * SoqlQuery.MaximumLimit); offsetResults = Client.read <IEnumerable <T> >(SodaUri.ForQuery(Host, Identifier, soqlQuery)); } return(allResults); } }