Orderby语法ASC

时间:2011-12-03 16:33:51

标签: linq entity-framework linq-to-entities

ASC订购的正确语法是什么 ?

错误1当前上下文中不存在名称“ASC”

 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;

3 个答案:

答案 0 :(得分:42)

  • .OrderBy(x => x.City)升序。
  • .OrderByDescending(x => x.City)降序排列

答案 1 :(得分:0)

使用Distinct时使用此查询。

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

它对我有用。

答案 2 :(得分:0)

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

输出IEnumerable集 您可以使用var或任何类型创建此集合