/// <summary> /// Adds <see cref="SqlOrderColumn"/> columns to the given order collection by parsing each value in the given sort expression /// </summary> /// <param name="collection"></param> /// <param name="sortExpression">A SQL sort expression such as 'FirstName, LastName DESC'.</param> public static void Add(this ICollection <SqlOrderColumn> collection, string sortExpression) { var parts = sortExpression.Split(','); foreach (var part in parts) { collection.Add(SqlOrderColumn.Parse(part)); } }
public static SqlOrderColumn Parse(string s) { var parts = s.Split(' '); var result = new SqlOrderColumn(); result.ColumnName = parts[0]; if (parts.Length == 2) { result.SortDirection = parts[1].StartsWith("ASC", StringComparison.OrdinalIgnoreCase) ? DbSortDirection.Ascending : DbSortDirection.Descending; } return(result); }