Sveta26
Sveta26

Reputation: 541

Orderby syntax ASC

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;

Upvotes: 16

Views: 31461

Answers (3)

Ata Hoseini
Ata Hoseini

Reputation: 137

IEnumerable<t_HomeRequets> homeRequets = cnx.t_HomeRequets
    .Where(x => x.HomeRequestId > DeletedId && x.BuildingId== BuildingId)
    .OrderByDescending(s => s.HomeRequestId)
    .AsEnumerable<t_HomeRequets>();

Outputs an IEnumerable set you can create this set with a var or any type

Upvotes: 0

Sharlin K
Sharlin K

Reputation: 11

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.

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1039498

  • .OrderBy(x => x.City) for ascending order.
  • .OrderByDescending(x => x.City) for descending order

Upvotes: 56

Related Questions