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 NHibernate
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With