AFSDKExtension.ChunkedBy(T) Method
- Last UpdatedNov 18, 2025
- 4 minute read
- PI System
- AF SDK 2024 R2
- Developer
This extension method breaks up search results into chunks to make it easier to
page through and process IEnumerableT collections in chunks.
Namespace: OSIsoft.AF
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
public static IEnumerable<IList<T>> ChunkedBy<T>( this IEnumerable<T> enumerable, int chunkSize )
<ExtensionAttribute> Public Shared Function ChunkedBy(Of T) ( enumerable As IEnumerable(Of T), chunkSize As Integer ) As IEnumerable(Of IList(Of T)) Dim enumerable As IEnumerable(Of T) Dim chunkSize As Integer Dim returnValue As IEnumerable(Of IList(Of T)) returnValue = enumerable.ChunkedBy(chunkSize)
public: [ExtensionAttribute] generic<typename T> static IEnumerable<IList<T>^>^ ChunkedBy( IEnumerable<T>^ enumerable, int chunkSize )
[<ExtensionAttribute>] static member ChunkedBy : enumerable : IEnumerable<'T> * chunkSize : int -> IEnumerable<IList<'T>>
Parameters
- enumerable
- Type: System.Collections.GenericIEnumerableT
The IEnumerableT collection being broken into chunks of items. - chunkSize
- Type: SystemInt32
The size of the list of returned items for each chunk of items from the collection.
Type Parameters
- T
- The type of items the list being broken into chunks.
Return Value
Type: IEnumerableIListTReturns a list of items of chunkSize from the enumerable collection. The last chunk of items maybe less than the specified chunk size.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableT. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Exceptions
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | This exception is thrown if the chunkSize parameter is less than or equal to zero. |
Remarks
Many times it is more efficient to page through and process a page of search results
in chunks instead of the entire collection. For example, the DeleteElements(PISystem, IListGuid)
method takes a list of IDs of the elements to be deleted. Instead of passing in the entire
list from the search, it is more efficient to break the results into smaller chunks to be deleted.
Examples
// This example demonstrates how to use efficiently delete elements using // AFElementSearch and the DeleteElements method. // Get the Database PISystems myPISystems = new PISystems(); PISystem myPISystem = myPISystems.DefaultPISystem; AFDatabase myDB = myPISystem.Databases.DefaultDatabase; // Search for the elements to be deleted. using (var search = new AFElementSearch(myDB, "FindElements", @"Template:'MyTemplate'")) { search.CacheTimeout = TimeSpan.FromMinutes(10); // Get a list of IDs of elements to be deleted in pages of 100. foreach (IList<Guid> pageOfIds in search.FindObjectIds().ChunkedBy(100)) { AFElement.DeleteElements(myPISystem, pageOfIds); } }
' This example demonstrates how to use efficiently delete elements using ' AFElementSearch And the DeleteElements method. ' Get the Database Dim myPISystems As PISystems = New PISystems() Dim myPISystem As PISystem = myPISystems.DefaultPISystem Dim myDB As AFDatabase = myPISystem.Databases.DefaultDatabase ' Search for the elements to be deleted. Using search As New AFElementSearch(myDB, "FindElements", "Template:'MyTemplate'") search.CacheTimeout = TimeSpan.FromMinutes(10) ' Get a list of IDs of elements to be deleted in pages of 100. For Each pageOfIds As IList(Of Guid) In search.FindObjectIds().ChunkedBy(100) AFElement.DeleteElements(myPISystem, pageOfIds) Next End Using
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.