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

Forums / Developing with Sitefinity / How to get multiple ChooseOptions related to the Dynamic Module Type item

How to get multiple ChooseOptions related to the Dynamic Module Type item

3 posts, 0 answered
  1. Kolia
    Kolia avatar
    3 posts
    Registered:
    25 Jun 2012
    04 Feb
    Link to this post

    I have the Dynamic Module Type DMType1 that includes field Field1 that has type of multiple chooses (Choose1,Choose2,Choose3).This selected chooses CMS store in the separate table (with dynamic name) where "base_id" column  is equals to the  DMType1 table item "base_id", column "seq" contain the choose number value, and "value" columns contain the string value for the choose .

    I have my own API that retrieve this DMType1 my using DynamicModuleManager to get them from CMS DB, and to get Field1 value, I need to use:

    var fild1Value = ((DynamicContent)dmType1 ).GetValue<ChoiceOption[]>("Field1")

    but it is very slow because I have lots DMType1 items, so I need to get all ChoiceOptions related to the DMType1 items  in one request to DB and then map options to the item by "base_id" (dmType1.Id).  

     

    What the correct way to do it?

  2. Georgi Dimitrov
    Georgi Dimitrov avatar
    9 posts
    Registered:
    01 Sep 2016
    09 Feb
    Link to this post
    Hi Kolia,

    Thank you for contacting us.

    You can achieve desired behavior using DataAccess FetchStrategies, see the sample code bellow:
    var manager = DynamicModuleManager.GetManager();
    var type2Type = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Module1.Type1");
     
    var fetchStrategy = ((IOpenAccessDataProvider)manager.Provider).GetContext().FetchStrategy;
    if (fetchStrategy == null)
    {
        fetchStrategy = new FetchStrategy();
    }
    fetchStrategy.LoadWith("Telerik.Sitefinity.DynamicTypes.Model.Module1.Type1", "Choices");
     
    var items = manager.GetDataItems(type2Type).Where(i => i.Status == ContentLifecycleStatus.Live).ToList();

    Please do not hesitate to contact me again if you need any additional information.

    Regards,
    Georgi Dimitrov
    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. Kolia
    Kolia avatar
    3 posts
    Registered:
    25 Jun 2012
    10 Feb in reply to Georgi Dimitrov
    Link to this post

    Hi Georgi,

    Thank you for the reply this is exactly what I was looking for.

3 posts, 0 answered