public static SqlQuery ApplySort(this SqlQuery query, SortBy sortBy) { if (sortBy != null) return ApplySort(query, sortBy.Field, sortBy.Descending); return query; }
/// <summary> /// Reads the JSON representation of the object.</summary> /// <param name="reader">The <see cref="JsonReader"/> to read from.</param> /// <param name="objectType"> /// Type of the object.</param> /// <param name="existingValue"> /// The existing value of object being read.</param> /// <param name="serializer"> /// The calling serializer.</param> /// <returns> /// The object value.</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) return null; var sortBy = new SortBy(); if (reader.TokenType != JsonToken.String) throw new JsonSerializationException("Unexpected end when deserializing object."); var field = ((string)reader.Value).TrimToEmpty(); if (field.EndsWith(" DESC", StringComparison.OrdinalIgnoreCase)) { sortBy.Field = field.Substring(0, field.Length - 5).TrimToEmpty(); sortBy.Descending = true; } else sortBy.Field = field; return sortBy; }
protected virtual void ApplySortBy(SqlQuery query, SortBy sortBy) { query.ApplySort(sortBy.Field, sortBy.Descending); }