我应该如何在不同的实体中使用order by

时间:2016-04-16 09:00:20

标签: sql .net linq-to-entities entity sql-order-by

我有这段代码

ORDER BY c.SenderId

我应该如何添加“按顺序排列”:

type="text/css"

1 个答案:

答案 0 :(得分:0)

在其末尾添加OrderBy

   var chats = (from c in _entities.Chats
    where c.SenderId == userId || c.ReceiverId == userId

        select new ChatList()
         {
          Logo = c.SenderId != userId ? c.Company.LogoUrl:c.Company1.LogoUrl,
          Name = c.SenderId != userId? c.Company.CompanyPersonName:c.Company1.CompanyPersonName,
        UserId = c.SenderId!=userId ?c.Company.CompanyId : c.Company1.CompanyId 
        }
    ).Distinct().OrderBy(x => x.UserId)