More in this section

Forums / Developing with Sitefinity / Getting a dynamic collection

Getting a dynamic collection

2 posts, 0 answered
  1. Steve
    Steve avatar
    3037 posts
    03 Dec 2008
    20 Mar 2012
    Link to this post
    I have the code snippet from the backend to get a collection of my module item, but it's returning my 8 results instead of the 4 I see in the backend. 

    ...unless I call a .Distinct(), then I get my 4 back

    Any idea what the problem might be?
    public void OnRotator_NeedsDataSource(object sender, Telerik.Web.UI.RadListViewNeedDataSourceEventArgs e) {
                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
                Type rotatorItemType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Rotator.RotatorItem");
                // This is how we get the collection of Rotator Item items
                var items = dynamicModuleManager.GetDataItems(rotatorItemType);
                var data = (from r in items.ToList()
                            select new {
                                Image1 = r.GetValue("Image1"),
                                Image2 = r.GetValue("Image2"),
                                SlideUrl = r.GetValue("SlideUrl"),
                                SliderText = r.GetValue("SliderText"),
                                Index = r.GetValue("Index")
                ((RadListView)sender).DataSource = data.Distinct().OrderBy(x => x.Index);
    (So I'm transforming the results in order to sort with Linq)...but w/out the last Distinct at the bottom my results are duplicated

  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    28 Aug 2017
    20 Mar 2012
    Link to this post
    Hello Steve,

    Most likely you're also getting the master copies of the items, can you please try filtering for the Live status and items that are Visible like this:

    var items = dynamicModuleManager.GetDataItems(rotatorItemType).Where(di => di.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && di.Visible == true);

    Boyan Barnev
    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
2 posts, 0 answered