IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
When returning a collection of items in a Sitefinity CMS web service, you should always wrap that collection inside of a CollectionContex<T> object, which provides service client with some additional information about the collection.
The following diagram illustrates CollectionContext<T> class:
CollectionContext is a generic type, so when declaring it we need to specify the generic argument which is the type of the items this collection holds.
For example, if we are returning a collection of ResourceEntry objects, we would declare CollectionContext object as follows: CollectionContext<ResourceEntry> on the other hand, if our collection is made of Product object, we would declare CollectionContext object like this:
CollectionContext<Product>
CollectionContext class has three public properties:
private
CollectionContext<ResourceEntry> GetResourcesInternal(
string
cultureName,
classId,
provider,
sort,
int
skip,
take,
filter)
{
var manager = Res.GetManager(provider);
CultureInfo cultureInfo = GetCultureInfo(cultureName);
var query = from resoruce
in
manager.GetResources(cultureInfo)
where resoruce.ClassId == classId
select resoruce;
// extender takes care of it.
if
(!
.IsNullOrEmpty(sort))
query = query.OrderBy(sort);
// this is where the quer the query is executed.
totalCount = query.Count();
// wont fire the process again, when marked as IEnumerable.
var items = query.AsEnumerable().Skip(skip).Take(take);
var collectionContext =
new
CollectionContext<ResourceEntry>(items)
TotalCount = totalCount
};
return
collectionContext;
}
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important