LINQ sorting anonymous types?

前端 未结 4 1803
小鲜肉
小鲜肉 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:21

    If I've understood your question correctly, you want to do this:

    from e in linq0
    order by (e.User.FirstName + " " + e.User.LastName).Trim()) descending 
    select 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)
    }
    

提交回复
热议问题