This is a migrated thread and some comments may be shown as answers.

Fluent API Ordering of One-to-Many

1 Answer 92 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
John
Top achievements
Rank 1
John asked on 26 Jul 2011, 10:57 AM
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>

1 Answer, 1 is accepted

Sort by
0
Accepted
PetarP
Telerik team
answered on 29 Jul 2011, 10:33 AM
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!

Tags
Development (API, general questions)
Asked by
John
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Share this question
or