What is the correct syntax to order by ASC ?
Error 1 The name 'ASC' does not exist in the current context
public IEnumerable<DTO> GetGrid(String ShipNumber)
{
try
{
ORepository rep = new ORepository();
var query = rep.GetAll()
.Where(x => x.SHIP == ShipNumber)
.Orderby (x.City ASC)
.Select(g => new DTO
{
CUSTOMER_NAME = g.CUSTOMER_NAME,
CITY = g.CITY,
SHIP = g.SHIP,
});
return query;
The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.
If you want to sort some of the data in ascending order and other data in descending order, then you would have to use the ASC and DESC keywords. SELECT * FROM table ORDER BY column1 ASC, column2 DESC; That is how to use the ORDER BY clause in SQL to sort data in ascending order.
The ORDER BY statement in SQL is used to sort the fetched data in either ascending or descending according to one or more columns. By default ORDER BY sorts the data in ascending order. We can use the keyword DESC to sort the data in descending order and the keyword ASC to sort in ascending order.
You can use the ASC and DESC keywords to specify ascending (smallest value first) or descending (largest value first) order. The default order is ascending. For DATE and DATETIME data types, smallest means earliest in time and largest means latest in time.
.OrderBy(x => x.City)
for ascending order..OrderByDescending(x => x.City)
for descending orderIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With