Sorting lazy loaded collections

11 posts, 2 answers
  1. Robert
    Robert avatar
    40 posts
    Member since:
    Jul 2008

    Posted 17 Feb 2009 Link to this post

    Anyone know how I can specify an order by clause for queries that are generated by OpenAccess for lazy loaded collections?

    Thanks,
    Robert
  2. Answer
    Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 19 Feb 2009 Link to this post

    Hi Robert,
    If the collection is mapped to a join table the ordering stays the same as you added the objects.

    If you map the collection to backward reference you can set a static ordering in  the mapping. This can not be changed at runtime. To use case specific ordering you have to implement a query in a property.

    I have attached an example that shows both cases.

    For changing the ordering in the mapping you can use this mapping settings:

              <class name="A">
                <field name="bs">
                  <collection>
                    <extension key="inverse" value="{auto}" />
                    <extension key="ordering" value="name desc" />
                  </collection>
                </field>
              </class>

    The value can contain fields of the object itself but also fields of referenced objects by specifying the path.

    All the best,
    Jan Blessenohl
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Robert
    Robert avatar
    40 posts
    Member since:
    Jul 2008

    Posted 19 Feb 2009 Link to this post

    Works like a charm!  Is there a way to set this in the Wizards?  I looked and didn't find any and perhaps therein lies my error, in relying on the UI too much.  However, in a scan of the docs, using the keyword "ordering" I didn't find anything there either.  Is this functionality documented anywhere?

    Thanks,
    Robert
  5. Robert
    Robert avatar
    40 posts
    Member since:
    Jul 2008

    Posted 13 Apr 2009 Link to this post

    Hi There,

    I have  a situation where I have a lazy loaded collection I'd like to order but the Order By field name is not immediately available on the object type of the collection.  The sort field is in a referenced table so how do I sort on it?  I tried a few things and couldn't find one that worked.

    Eg.  ProductItem
                   Manufacturers collection of Manufacturer
    Manufacturer refers to a FIrm table which has a field of Name on which we'd like to sort on.

    Thanks,
    Robert
  6. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 14 Apr 2009 Link to this post

    Hello Robert,
    Using the reference name dot fieldname should work.

           <class name="A">
                <field name="bs">
                  <collection>
                    <extension key="inverse" value="{auto}" />
                    <extension key="ordering" value="flrm.name desc" />
                  </collection>
                </field>
              </class>

    Sincerely yours,
    Jan Blessenohl
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  7. Robert
    Robert avatar
    40 posts
    Member since:
    Jul 2008

    Posted 15 Apr 2009 Link to this post

    I can't seem to get this to work.  Judgeing by the error messages I'm getting, it seems as though the order by doesn't work because a join is not occuring to lowest level table on which I need to sort.  Perhaps this lower level table is being lazy loading and as such isn't being included in the original query.

    Do I need to create a fetch plan or something to ensure that that child tables are always included in queries?

    Thanks,
    Robert
  8. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 16 Apr 2009 Link to this post

    Hello Robert,
    I have looked into your problem and found some weird behavior as well. I will dig into it tomorrow and see if I can find a way for your to use it.

    Sincerely yours,
    Jan Blessenohl
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  9. Answer
    Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 20 Apr 2009 Link to this post

    Hello Robert,
    We have fixed your problem an we will try to give you a nightly build if it is urgent for you.

    Regards,
    Jan Blessenohl
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  10. Robert
    Robert avatar
    40 posts
    Member since:
    Jul 2008

    Posted 20 Apr 2009 Link to this post

    Excellent!  It is not urgent.  When can we expect another public release?

    Also, it sounds like this was a bug.  Does that mean there are some points coming my way? ;-)
  11. Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 21 Apr 2009 Link to this post

    Hi Robert,
    Your Telerik points were updated.

    Regards,
    Dimitar Kapitanov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  12. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 24 Apr 2009 Link to this post

    Hello Robert,
    The custom build is now available for download. Please login into the telerik web page and browse the download section.

    Best wishes,
    Jan Blessenohl
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top
DevCraft banner