0
如何在一個查詢中對EF返回的實體的內部集合進行排序?如何在由EF返回的實體中對內部列表進行排序?
public abstract class BatchOrder
{
//..
public virtual ICollection<Order> Orders { get; set; }
//..
}
我可以做這樣的事情:
var orders = DataContext.Orders
.Where(o => o.BatchOrderId == batchOrderId)
.OrderBy(o => o.SequenceNo)
.ToList();
var bmo = DataContext.BatchOrders
.Include("Track")
.Include("Customer")
.OfType<BatchMoneyOrder>()
.AsExpandable()
.Where(o => o.Id == batchOrderId)
.FirstOrDefault();
bmo.Orders = orders;
,但是這不會是這樣做的有效途徑。 我也檢查this solution,但它無法正常工作。
看看這個主題: http://stackoverflow.com/questions/3471588/how-to-sort-a-collection-based-on-a-subcollection-property, http://stackoverflow.com/問題/ 4156949/ef4-linq-ordering-parent-and-all-child-collections-with-eager-loading-include, http://stackoverflow.com/questions/3565249/ordering-sub-items-within-ordered -items-IN-A-LINQ到實體查詢 – Mentoliptus