New Posts New Posts RSS Feed: Lazy load sort order
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Lazy load sort order

 Post Reply Post Reply
Author
Togas View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Jul-2011
Location: Minneapolis
Posts: 11
Post Options Post Options   Quote Togas Quote  Post ReplyReply Direct Link To This Post Topic: Lazy load sort order
    Posted: 08-Aug-2011 at 7:23am
Is there a way to set the sort order when you are using lazy loading?
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 09-Aug-2011 at 3:45pm
Hi Togas,
 
Try
 
aCustumer.Orders.OrderBy(ord => ord.Freight)
 
Regards,
   Silvio.
Back to Top
Togas View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Jul-2011
Location: Minneapolis
Posts: 11
Post Options Post Options   Quote Togas Quote  Post ReplyReply Direct Link To This Post Posted: 10-Aug-2011 at 7:16am
Silvio,

Where would I put that?  My initial thought was that should be part of my initial load query but my child table isn't an option when I query the parent table and I also noticed you are only referencing a single customer.

The 2 tables are linked in my model
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 10-Aug-2011 at 11:39am
Hi Togas,
I assume that if you want to sort the order of a navigation property (i.e. lazy loading) you are probably binding it to something.
If you want to load related entities during your initial load query, then you will need to use .Include:
 
var initialLoadQuery = mgr.Customer
                          .Include("Orders");
 
in the case above, Orders are not being ordered because it's not bound to anything. (it was simply loaded in the EntityCache using eager loading)
 
Could you explain in detail what you are trying to accomplish, so I can better understand your issue?
 
Regards,
   Silvio.
Back to Top
Togas View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Jul-2011
Location: Minneapolis
Posts: 11
Post Options Post Options   Quote Togas Quote  Post ReplyReply Direct Link To This Post Posted: 10-Aug-2011 at 11:50am
Your assumption was correct, I'm binding to a datagrid.  It's a basic Master-Detail type page.






<sdk:DataGrid AutoGenerateColumns="False" 
ItemsSource="{Binding SelectedOrder.OshkoshEquipments}"
SelectedItem="{Binding SelectedEquipment, Mode=TwoWay}">
...

</sdk:DataGrid>


Here is the relevant code from my view model

Public Property OshkoshOrders As ObservableCollection(Of Oshkosh)
Private Sub LoadData
      OshkoshOrders = New ObservableCollection(Of Oshkosh)

      Dim qOrders = _mgr.Oshkoshes
      qOrders.ExecuteAsync(Sub(o)
                             If o.HasError Then
                               Throw New InvalidOperationException("Query failed")
                             End If
                             o.Results.ForEach(Sub(oe)
                                                 OshkoshOrders.Add(oe)
                                               End Sub)

                             SelectedOrder = OshkoshOrders.FirstOrDefault
                           End Sub)
End Sub



Edited by Togas - 10-Aug-2011 at 11:53am
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 15-Aug-2011 at 12:17pm
Hi Togas,
 
Since you're doing the binding to the DataGrid in the XAML, you will need to use a CollectionViewSource. There you can set the sort order there and then bind it to your DataGrid.
 
Take for instance our Silverlight Tour of DevForce sample (in the DevForce Resource Center).
 
Instead of binding the Orders of currentEmployee directly into the DataGrid
 
<sdk:DataGrid Name="EmployeeOrdersGrid"
              ItemsSource="{Binding ElementName=EmployeeDataForm,
                                    Path=CurrentItem.Orders}" />
 
 
you'd bind the Orders to the CollectionViewSource, sort it, and bind the CollectionViewSource to the DataGrid
 
 
<Grid.Resources>
  <CollectionViewSource x:Key="OrdersViewSource" Source="{Binding ElementName=EmployeeDataForm,
                                                                   Path=CurrentItem.Orders}">
    <CollectionViewSource.SortDescriptions>
      <scm:SortDescription PropertyName="Freight"/>
    </CollectionViewSource.SortDescriptions>
  </CollectionViewSource>
</Grid.Resources>
 
...
 
<sdk:DataGrid Name="EmployeeOrdersGrid"
              ItemsSource="{Binding Source={StaticResource OrdersViewSource}}"
/>
 
Regards,
   Silvio.
Back to Top
Togas View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Jul-2011
Location: Minneapolis
Posts: 11
Post Options Post Options   Quote Togas Quote  Post ReplyReply Direct Link To This Post Posted: 15-Aug-2011 at 12:44pm
Perfect

Thanks Silvio
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down