ASC (order by syntax)

entity-framework linq linq-to-entities

Question

What is the appropriate syntax for ordering using ASC?

Error 1: The term "ASC" is missing from the 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 a higher order.
  • .OrderByDescending(x => x.City) to sort in reverse
44
12/3/2011 4:35:24 PM

Popular Answer

When using Distinct, use this query.

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

I found it effective.



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