Does EF have ordered collections? The equivalent of list in the NHibernate Bag Vs Set Vs List world
Does the Entity Framework 4 have ordered collections?
For example my Order has a property that is a collection of OrderItems, but the order is important and I would rather not sort them before I access them.
See Nhibernate for an example: List vs Set vs Bag in NHib开发者_开发技巧ernate
It doesn't. You can force an order in a couple of ways however :
This answer explains one EF4 LINQ Ordering Parent and all child collections with Eager Loading (.Include()) (kind of)
More simply, if you are querying a single order, you can do so with the orderlines ordered in a specifc way:
var thing = _repo.GetOrder(id)
.Select(item =>
new { item, ord = item.orderlines.OrderBy(o => o.orderbythis) }
).FirstOrDefault().item;
精彩评论