How to get multiple ChooseOptions related to the Dynamic Module Type item
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?
Hi
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();
Hi Georgi,
Thank you for the reply this is exactly what I was looking for.