Using OrderBy with fluent API

Posted by Community Admin on 04-Aug-2018 22:17

Using OrderBy with fluent API

All Replies

Posted by Community Admin on 23-Nov-2011 00:00

I developed a slideshow widget that uses images from a particular album and I need a way to control the order the slides are displayed.
I have tried, unsuccessfully, to use OrderBy and use Titles of slide01, slide02 etc.
Can anyone see what I am missing? The OrderBy seems to have no effect...

public DataTable GetImages()
        
            string title = this.AlbumTitle;
            DataTable ImagesTable = new DataTable("ImagesTable");
            ImagesTable.Columns.Add("PhotoUrl", typeof(string));
            ImagesTable.Columns.Add("Title", typeof(string));
            ImagesTable.Columns.Add("AltText", typeof(string));
 
            //get IQueryable of images from the Fluent API.
            var images = App.WorkWith().Images()
                .Where(
                (w) => w.Parent.Title == title &&
                        w.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live)
                    .OrderBy(w => w.Title)
                    .Get();
            foreach (Telerik.Sitefinity.Libraries.Model.Image v in images)
            
                string photoUrl = v.MediaUrl;
                ImagesTable.Rows.Add(new string[] photoUrl, v.Title.ToString(), v.AlternativeText.ToString() );
            
 
            return ImagesTable;
        

Posted by Community Admin on 23-Nov-2011 00:00

Hi Scott,

Shouldn't you just do the Get() first and then the OrderBy?
Or like this:

foreach (Telerik.Sitefinity.Libraries.Model.Image v in images.OrderBy(w=>w.Title)
   string photoUrl = v.MediaUrl;
   ImagesTable.Rows.Add(new string[] photoUrl, v.Title.ToString(), v.AlternativeText.ToString() );
  
return ImagesTable;

Regards,
Daniel

Posted by Community Admin on 28-Nov-2011 00:00

Thanks, Daniel! That works great...

Posted by Community Admin on 12-Apr-2012 00:00

I have a bit column that I wanted to order by values of true or 1 in this column.  Is there a  way to get the name of the dynamic module field for the OrderBy directive? .OrderBy(z => z.WhatHere)
In my case the column is named Default.  



Posted by Community Admin on 16-Apr-2012 00:00

W3: It's a slightly different process for Dynamic Modules than it is for built in modules such as Albums. I'm still new to working with Dynamic Modules, but I think this will work for you:

// required for GetValue()
using Telerik.Sitefinity.Model;

.OrderBy(d => d.GetValue(
"Default"))

Since it is a dynamic field, you cannot reference it as you would a strongly typed field (e.g. d.Default), instead you have to use a method such as GetValue() that can resolve the dynamic name for you.

Note that GetValue won't return the expected result if you are testing a dynamic field that was populated with a drop down. That's a different quirky process that is more suitable for a different discussion thread.

This thread is closed