Try our conversational search powered by Generative AI!

Get single image from gallery

Vote:
 
Is there a better way to implement this?
 
var image =
    ImageGalleryHandler.Instance.GetImages(new ImageGalleryCollection(new List<ImageGallery> { blogEntry.ImageGallery }),
                                           1,
                                           1,
                                           EntityStatus.Approved).FirstOrDefault();

    

#56615
Jan 30, 2012 14:40
Vote:
 

nice formatting :)

#56616
Jan 30, 2012 14:41
Vote:
 

Hi Valdis, 

It looks like you've got two solutions. Either the one you've posted above, or by creating a query: 

ImageQuery imageQuery = new ImageQuery();
imageQuery.ImageGallery = new ImageGalleryCriterion();
imageQuery.ImageGallery.ID = new IntegerCriterion();
imageQuery.ImageGallery.ID.Value = CurrentImageGallery.ID;
ImageCollection images = QueryHandler.Instance.GetQueryResult<Image, ImageCollection>(imageQuery, 1, 1);

I would probably go for your solution as the GetImages method uses ImageGalleryFactory directly (instead of the QueryFactory), and from a performance point of view it probably has its upsides.

I find it a bit strange that there isn't an overload for the GetImages method that accepts an ImageGallery instead of an ImageGalleryCollection, but I'm sure there's a good reason for it :)

Hope this helps!

Karoline

#56622
Jan 31, 2012 9:02
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.