开发者

Does EF have ordered collections? The equivalent of list in the NHibernate Bag Vs Set Vs List world

开发者 https://www.devze.com 2023-01-13 08:44 出处:网络
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 acce

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号