LINQ sorting anonymous types?

前端 未结 4 1921
小鲜肉
小鲜肉 2021-02-06 07:17

How do I do sorting when generating anonymous types in linq to sql?

Ex:

from e in linq0
order by User descending /* ??? */
select new
{
   Id = e.Id,
            


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-06 07:20

    Would this work, as a way of avoiding Jon's select...into?

    from e in linq0
    let comment = new
        {
           Id = e.Id,
           CommentText = e.CommentText,
           UserId = e.UserId,
           User = (e.User.FirstName + " " + e.User.LastName).Trim()),
           Date = string.Format("{0:d}", e.Date)
        }
    orderby comment.User descending
    select comment
    

提交回复
热议问题