ASC (order by syntax)

entity-framework linq linq-to-entities

Question

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;
1
12
12/3/2011 4:33:51 PM

Accepted Answer

  • .OrderBy(x => x.City) for ascending order.
  • .OrderByDescending(x => x.City) for descending order
44
12/3/2011 4:35:24 PM

Popular Answer

Use this query when you use Distinct.

var result = ctx.tblCity.AsNoTracking()
 .Where(s => s.City== "Chennai")                                 
 .Select(s => new Area { Name = s.AreaName})                                 
 .Distinct().OrderBy(s => s.Name).ToList();

It worked for me.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow