[英]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? 实体框架4是否订购了集合?
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. 例如,我的Order有一个属性是OrderItems的集合,但顺序很重要,我宁愿在访问它们之前不对它们进行排序。
See Nhibernate for an example: List vs Set vs Bag in NHibernate 有关示例,请参阅Nhibernate:NHibernate中的List vs Set vs Bag
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) 这个答案解释了一个EF4 LINQ Ordering Parent和所有具有Eager Loading(.Include())的子集合 (种类)
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.