+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / OrderBy issue when retrieving child items in dynamic data module

OrderBy issue when retrieving child items in dynamic data module

3 posts, 1 answered
  1. Chris
    Chris avatar
    2 posts
    Registered:
    17 Jan 2013
    27 Mar 2015
    Link to this post

    We are running Sitefinity 7.3 and I have created a Module called StoreCategories in Module Builder. Each StoreCategory has children of type StoreProducts. I am using the following function to successfully retrieve the StoreProducts for a given StoreCategory.

     

    public IQueryable<DynamicContent> RetrieveStoreProducts(DynamicContent Category)
            {
                var providerName = String.Empty;
     
                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
                IQueryable<DynamicContent> products = dynamicModuleManager.GetChildItems(Category).Where(i => i.Status == ContentLifecycleStatus.Live && i.Visible == true);
                return products;
            }

    My question is that I need to order the results by a field called weight that was defined in module builder.

    I have tried something like this

    IQueryable<DynamicContent> products = dynamicModuleManager.GetChildItems(Category).Where(i => i.Status == ContentLifecycleStatus.Live && i.Visible == true).OrderyBy("Weight");

    but I am getting an error stating "No 'Weight' member found in type 'Telerik.Sitefinity.DynamicModules.Model.DynamicContent'" The weight field is definitely defined in Module builder for StoreProducts but I suspect that I am missing something in my logic. Any help would be greatly appreciated.

     Thank you.

     

  2. Kaloyan
    Kaloyan avatar
    272 posts
    Registered:
    08 Dec 2016
    01 Apr 2015
    Link to this post
    Hello Chris,

    I have answered you in the ticket that you have opened for this issue. Feel free to share the answer with our community.

    Regards,
    Kaloyan
    Telerik
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Chris
    Chris avatar
    2 posts
    Registered:
    17 Jan 2013
    01 Apr 2015 in reply to Kaloyan
    Link to this post

    So it turns out that the answer was to not use the dynamicModuleManager.GetChildItems(Category) approach to retrieve the StoreProduct objects but rather to query the StoreProducts directly and specify the parent's id in a Where clause. This should allow you to use OrderBy. See the amended method below which works correctly.

     

    public IQueryable<DynamicContent> RetrieveStoreProducts(DynamicContent Category)
            {
                var providerName = String.Empty;
     
                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
     
                Type storeProductType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.StoreCategories.StoreProduct");
     
                // This is how we get the collection of Store Product items
                IQueryable<DynamicContent> storeProducts = dynamicModuleManager.GetDataItems(storeProductType)
                                                        .Where(a => a.SystemParentId == Category.Id)
                                                        .Where(i => i.Status == ContentLifecycleStatus.Live && i.Visible == true)
                                                        .OrderBy(o => o.GetValue<decimal?>("Weight"));
     
                return storeProducts;
            }

    Answered
3 posts, 1 answered