Getting a dynamic collection

Posted by Community Admin on 04-Aug-2018 03:59

Getting a dynamic collection

All Replies

Posted by Community Admin on 20-Mar-2012 00:00

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

Steve

Posted by Community Admin on 20-Mar-2012 00:00

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);


Greetings,
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

This thread is closed