Getting related data and childs dinamically in code
Hi,
I have created a content type that has both a child and a related data column. From the sample codes I saw in your site I can see that you need to "hardcode" the columns in order to retrieve the information.
docs.sitefinity.com/example-filter-dynamic-content-items-by-dynamic-field
Is there any way of getting this columns dinamically and then request for each type or is there a way to get the complete object like Lazy loading option in EF.
Regards,
Could you give me some feedback about this capability?
Hi Setxi,
In order to get a list of the fields of your content type dynamically you can try the following code:
// Set the provider name for the DynamicModuleManager here. All available providers are listed in
// Administration -> Settings -> Advanced -> DynamicModules -> Providers
var providerName = String.Empty;
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
Type contenttypemtwoType = TypeResolutionService.ResolveType(
"Telerik.Sitefinity.DynamicTypes.Model.ModuleName.ContenttypemName"
);
// set your content type
var moduleBuilderManager = ModuleBuilderManager.GetManager(providerName);
var dynamicModuleType = moduleBuilderManager.Provider.GetDynamicModuleTypes()
.Where(t => t.TypeNamespace == contenttypemtwoType.Namespace).Single();
//.Where(t => t.TypeName == type.Name && t.TypeNamespace == type.Namespace).Single();
var fields = moduleBuilderManager.Provider.GetDynamicModuleFields().Where(f => f.ParentTypeId == dynamicModuleType.Id && f.SpecialType == FieldSpecialType.None);