how to get all content items of a special content type in orchad core

1k views Asked by At

I'm working with orchard core and I've written my own Apis. To get content items of a special content type I've used GetRecentContentItemsByContentTypeAsync() function. this function does not get all content items, but I need to get all to write a service with pagination. I would appreciate it if there is a solution... Thanks in advance

1

There are 1 answers

0
Dean Marcussen On BEST ANSWER

You probably will want to use inject the YesSql.ISession directly to create a more specific query.

Something like

var query = _session.Query<ContentItem, ContentItemIndex>(x => x.ContentType == "mycontenttype");

var count = await query.CountAsync(); // for pagination
var results = await query.Skip(0).Take(10).ListAsync();

or for a more complex set

using YesSql.Services;
var contentTypes = new [ "contenttype1", "contenttype2" ];
var query = _session.Query<ContentItem, ContentItemIndex>(x => x.ContentType.IsIn(contentTypes));