Using OrderBy with fluent API
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;
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;
Thanks, Daniel! That works great...
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.
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"
))