是否可以通过以下内容编写linq选择内部顺序:
ReservationDTO obj = new ReservationDTO();
obj.bookroomview = obj.bookroomview.GroupBy(a => a.RoomFloor)
.Select(a => obj.bookroomview
.Select(x => new { Amount = a.Select(b => b.ReservationRoomID).Count(), Name = a.Key })
.OrderBy(x => x.Amount)
).ToList().AsQueryable();
我的目标是选择所有obj.roombookview项目,但根据计算计算对它们进行排序。如果有可能我怎么写呢?
我的观点类:
public partial class Book_Room_View
{
public Nullable<int> ReservationID { get; set; }
public Nullable<System.DateTime> StartDate { get; set; }
public Nullable<System.DateTime> EndDate { get; set; }
public Nullable<int> ReservationRoomID { get; set; }
public string RoomName { get; set; }
}
答案 0 :(得分:0)
如果你要通过预订订购这些团体,我想这是正确的做法,你不需要计算特定属性,因为我猜你正在尝试,只需按值列表的顺序排序。
obj.bookroomview.GroupBy(a => a.RoomFloor)
.OrderBy(gr => gr.Count())
.Select(gr => new { Amount = gr.Count(), Name = gr.Key })
.AsQueryable();