我有以下课程:
public class Order
{
public int Oid {get; set;}
public DateTime OrderDate {get; set;}
public List<OrderDetails> OrderDetails {get; set;}
}
public class OrderDetail
{
public int Oid {get; set;}
public int Price {get; set;}
public Order Order {get; set;}
public EventSchedule EventSchedule {get; set;}
}
public class EventSchedule
{
public int Oid {get; set;}
public BaseEvent BaseEvent {get; set;}
public List<OrderDetail> OrderDetails {get; set;}
}
public class BaseEvent
{
public int Oid {get; set;}
public string Name {get; set;}
public List<EventSchedule> EventSchedules {get; set;}
}
我有以下代码:
var result = Database.Orders.Where(o => o.DateTime == dateTime);
现在,我想对result
:
case "Date":
result = (sortingOrder == "desc") ? result.OrderByDescending(c => c.OrderDate) : result.OrderBy(c => c.OrderDate);
break;
// the problem is here this code not works
case "EventName":
result = (sortingOrder == "desc") ? result.All(o=>o.OrderDetails.OrderBy(d=>d.EventSchedule.BaseEvent.Name)) : ...;
break;
有Order
一个集合OrderDetail
。OrderDetail
有EventSchedule
。而且,EventSchedule
有BaseEvent
。这可以按属性对Order
对象进行排序? Name
BaseEvent