Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Do you mean you want to order the child objects within each object?</p> <p>If so, there's a little info that might help here (though it looks nasty):</p> <p><a href="http://weblogs.asp.net/zeeshanhirani/archive/2008/07/28/sorting-child-collections-in-entity-framework.aspx" rel="nofollow">http://weblogs.asp.net/zeeshanhirani/archive/2008/07/28/sorting-child-collections-in-entity-framework.aspx</a></p> <blockquote> <p>I made a blog post earlier, where I discussed how to use AssociateWith method on DataLoadOptions to sort child collections on SQL server before they are loaded into memory. This option is only available in linq to SQL. In entity framework, in order to accomplish sorting on child collection, you have to use CreateSourceQuery method. CreateSourceQuery returns an objectquery that gets converted to SQL and send to the database. So if you want your child collections to be loaded differently such as sorted in a different order or apply filter, than you have to get access to ObjectQuery instance that is responsible for loading the child subcollection and modify the query to add ordering before ObjectQuery gets executed. CreateSourceQuery query method is available on EntityCollection and EntityReference.</p> <p>Below is an example that shows how to do that</p> </blockquote> <pre><code>var context = new NorthwindEntities(); var cus1 = context.Customers.Single(c =&gt; c.CustomerID == "ALFKI"); foreach (var order in cus1.Orders.CreateSourceQuery().OrderBy(o =&gt; o.ShipCity) { Console.WriteLine(order.ShipCity); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload