How to get multiple ChooseOptions related to the Dynamic Mod

Posted by Community Admin on 04-Aug-2018 10:30

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

All Replies

Posted by Community Admin on 04-Feb-2016 00:00

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?

Posted by Community Admin on 09-Feb-2016 00:00

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
 

Posted by Community Admin on 10-Feb-2016 00:00

Hi Georgi,

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

This thread is closed