To fetch a list of all Content entities of a specific content type, we can use the following methods
- Get the List using the parent ID (Content Type ID) of the content entity:
var query = Query.CreateQuery(entities => from e in entities
where e.DefinitionName == "M.Content"
&& e.Parent("ContentTypeToContent") == 35045
select e);
var queryResult = await MClient.Client().Querying.QueryAsync(query);
Where 35045 is the Parent ID.
- Get the list of all the entities of Content-Type using parent-children relation
//Get the Blog Type entity
IEntity blogType = await webMClient.Entities.GetAsync("M.ContentType.Blog", EntityLoadConfiguration.Full);
if (blogType == null)
{
Console.WriteLine("Blog Type is Null");
return;
}
//Get the Parent to many children relation
IParentToManyChildrenRelation parentToManyChildren = blogType.GetRelation<IParentToManyChildrenRelation>("ContentTypeToContent");
if (parentToManyChildren == null)
{
Console.WriteLine("Blog Type Children Relation is Null");
return;
}
//Get entity IDs of all the blog-type entities
var entityIds = parentToManyChildren.Children;
Refer to the blog post for more detail about other methods and how to find parent ID, etc: Get a List of all Content Entities of the Same Content Type in Sitecore Content Hub