Fluent API Ordering of One-to-Many

2 posts, 1 answers
  1. John
    John avatar
    5 posts
    Member since:
    Sep 2012

    Posted 26 Jul 2011 Link to this post

    Hi,

    I was wondering if there is a way to specify the ordering of list elements when defining a one-to-many association using the Fluent API?

    For example - an equivalent of the following which can be specified in the config file mapping.

    Thanks
    John

    <field name="studentList">
     <collection> <!-- ItemType is Student -->
       <extension key="ordering"
         value="addr.city ascending, addr.street ascending" />
     </collection>
    </field>
  2. Answer
    PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 29 Jul 2011 Link to this post

    Hello John,

     You can use the OrderBy method. Here is an example:

    string orderByClause = "Ascending myColum, descending OrderId";
                MappingConfiguration<Product> customerMapping = new MappingConfiguration<Product>();
                customerMapping.MapType().ToTable("Products");
                TestFluentMappingSource source = new TestFluentMappingSource();
                source.MappingConfigurations.Add(customerMapping);
     
                customerMapping.HasAssociation(x => x.Stores).OrderBy(orderByClause);
    Please have in mind that the OrderBy method is in the 
    Telerik.OpenAccess.Metadata.Fluent.Advanced namespace.

    Greetings,
    Petar
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. DevCraft banner
Back to Top