App.WorkWith().Albums().Images broken in 5.1?

Posted by Community Admin on 04-Aug-2018 19:28

App.WorkWith().Albums().Images broken in 5.1?

All Replies

Posted by Community Admin on 06-Aug-2012 00:00

From this link:
http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/modules/media-modules/images/managing-albums/querying-albums 


Upgrading to 5.1 seems to have broken  the ability to do App.WorkWith().Albums().Images

'Telerik.Sitefinity.Libraries.Model.Album' does not contain a definition for 'Images' and no extension method 'Images' accepting a first argument of type 'Telerik.Sitefinity.Libraries.Model.Album' could be found (are you missing a using directive or an assembly reference?)


thx


Posted by Community Admin on 06-Aug-2012 00:00

Oops, let me clarify, it's done by this exact code.


    public static List<Telerik.Sitefinity.Libraries.Model.Image> GetImagesByAlbumName(string albumName)
   
        var album = App.WorkWith().Albums().Where(a => a.Title == albumName).Get().FirstOrDefault();

        if (album != null)
            return album.Images.Where(x => x.Status == ContentLifecycleStatus.Live && x.Visible).OrderBy(x => x.Ordinal).ToList();
        else
            return new List<Telerik.Sitefinity.Libraries.Model.Image>();
   


album.Images generates the error.

Posted by Community Admin on 09-Aug-2012 00:00

Bumping.  

how do i retreive images from an album by album name?


thx

Posted by Community Admin on 14-Aug-2012 00:00

Hi, Chris.

In order to decrease the consumed memory and increase the overall performance of Sitefinity, several properties (in-memory collections) of given classes were replaced with extension methods that return the same data via IQueryable collections. See this page from the documentation.

One of these was the Album class. So Images is now an extension method of Album as shown here.

So your code needs to change just a bit:

public static List<Telerik.Sitefinity.Libraries.Model.Image> GetImagesByAlbumName(string albumName)
    
        var album = App.WorkWith().Albums().Where(a => a.Title == albumName).Get().FirstOrDefault();
 
        if (album != null)
            return album.Images().Where(x => x.Status == ContentLifecycleStatus.Live && x.Visible).OrderBy(x => x.Ordinal).ToList();
        else
            return new List<Telerik.Sitefinity.Libraries.Model.Image>();
    

Make sure to add this using statement:
using Telerik.Sitefinity.Modules.Libraries;

This should get you back in business.

Kind regards,
Randy Hodge
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 14-Aug-2012 00:00

Much appreciated, thanks for that link. 

cheers,
Chris


This thread is closed