Filter dynamic content types by related data items.
Hi All,
Quick question on Sitefinity API, how to filter dynamic Content types by related data items ?
Here is my code which didn't work for me.
var contentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.ContentModel.ContentModel");
var contentDataList = dynamicModuleManager.GetDataItems(contentType );
var FilteredItems = contentDataList.ToArray().Where(p =>
p.GetRelatedItems("Attraction").OfType<DynamicContent>().Any(s
=> s.GetValue<string>("Title").Equals("Museum")));
where "Attraction" is the related data items to ContentModel dynamic content type and I want to filter all content items by specific attraction related content title.
Thanks!!!
After more research, I found that "GetRelatedItems" is coming as null if the dynamic content types exceeds 200+ and works fine for 5-10 pieces of content. Is it a bug or because of performance Sitefiniy don't return Related data if the request has 200+ content items ?
Thanks.
Hi Uttam,
Can you please refer to the following article and try the sample we have provided there for querying dynamic content items by related data.
Regards,
Sabrie Nedzhip
Telerik
I am facing with a similar Problem and have not got the solution yet.
Please refer to the below mentoined line of code:
IQueryable<Telerik.Sitefinity.Lists.Model.ListItem> listItems = listManager.GetListItems().Where(li => li.Parent.Id == ListID && li.Status == ContentLifecycleStatus.Live && li.Visible == true && li.GetRelatedItems<DynamicContent>("ExpertType").FirstOrDefault().GetValue<string>("Title") == "Financial Team").OrderBy(x => x.Ordinal);
I am trying to filter list items with a dynamic module used as custom field on the list item but getting below mentioned error:
SubQueries involving non-persistent sources not supported : Telerik.Sitefinity.DynamicModules.Model.DynamicContent[].All(z => (z.FieldValue("Title") == "Financial Team"))
Please help.
Hi,
I need to filter by two related data values...
¿Is that possible?
Thanks in advance.
Hi,
Please use the below approach for filtering the items by related data: http://docs.sitefinity.com/example-query-dynamic-content-by-related-data
Here is also another sample code for more details on filtering dynamic modules by related pages:
Type schoolType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Schools.School"); var contentLinksManager = ContentLinksManager.GetManager(); // the type of your module which has Pages as related data string parentType = "Telerik.Sitefinity.DynamicTypes.Model.Schools.School"; // the ID of the Page you would like to filter by. Guid PageNodeId = new Guid("216665AC-33A7-6917-80C9-FF0000B37697"); // here you get the IDs of dynamic module items // which has as related data a Page with the specified ID var parentItemContentLinks = contentLinksManager.GetContentLinks() .Where(c => c.ParentItemType == parentType && c.ChildItemId == PageNodeId) .Select(c => c.ParentItemId).ToList(); // here you get the filtered dynamic module items by their IDs var result = dynamicModuleManager.GetDataItems(schoolType) .Where(d => parentItemContentLinks.Contains(d.OriginalContentId) && d.Status == ContentLifecycleStatus.Live);