I was using IContentService because I was creating some content programmatically, but for retrieving published items I should be using the UmbracoHelper and IPublishedContentQuery - am I right?
As an example, say you have a Document Type called Player and each player has a property Age.
I have a custom RenderController for this doc type.
So, if I want to display a list of Players where Age = 30, should I be using the Search of the IPublishedContentQuery ?
With the IPublishedContentQuery (inject it from the dependency container of Umbraco in a registered service or in a .cshtml view using @inject) it is possible to get retrieve the model Player.
Umbraco generates models based on the DocTypes you created in the solution of the project. In this case your generated model is called: Player. You can then pass this generic model to an function of the IPublishedContentQuery like so:
//Replace with correct page id
int pageId = 0;
//Using the generic function
var player = publishedContentQuery.Content(pageId)?.DescendantOrSelf<Player>();
//Properties are now accessable
player.Age;
I just quickly put this here off the top of my head but I'm guessing this would work.
How to use IQuery<IContent> in ContentService.GetPagedChildren in v.13
Hi guys,
can you please give me a sample on how to use the filter option of the GetPagedChildren method of the ContentService?
I found some old threads, but they all use _sqlContext which might have been the case for older versions, but not for v.13?
Hi Vesselin,
Before I can give you an correct answer: Are you only option for retrieving published content?
In practice you should ONLY use the IContentService for creating and updating content.
If you want to retrieve content you can use the IPublishedContentQuery.
Hi Joppe,
good point.
I was using IContentService because I was creating some content programmatically, but for retrieving published items I should be using the UmbracoHelper and IPublishedContentQuery - am I right?
As an example, say you have a Document Type called Player and each player has a property Age.
I have a custom RenderController for this doc type.
So, if I want to display a list of Players where Age = 30, should I be using the Search of the IPublishedContentQuery ?
Thanks a lot!
Hi Vesselin,
With the IPublishedContentQuery (inject it from the dependency container of Umbraco in a registered service or in a .cshtml view using @inject) it is possible to get retrieve the model Player.
Umbraco generates models based on the DocTypes you created in the solution of the project. In this case your generated model is called:
Player
. You can then pass this generic model to an function of the IPublishedContentQuery like so:I just quickly put this here off the top of my head but I'm guessing this would work.
Let me know!
Greeting, Joppe
I ended up using the UmbracoHelper and then filtering the .Children() IPublishedContent collection which works great for me.
Thanks again for your help!
Cheers!
Greetings, Joppe
is working on a reply...