 | AFSDKExtensionChunkedByT Method |
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: 2.10.8.440
Syntaxpublic 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:
IEnumerableIListT
Returns 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
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
PISystems myPISystems = new PISystems();
PISystem myPISystem = myPISystems.DefaultPISystem;
AFDatabase myDB = myPISystem.Databases.DefaultDatabase;
using (var search = new AFElementSearch(myDB, "FindElements", @"Template:'MyTemplate'"))
{
search.CacheTimeout = TimeSpan.FromMinutes(10);
foreach (IList<Guid> pageOfIds in search.FindObjectIds().ChunkedBy(100))
{
AFElement.DeleteElements(myPISystem, pageOfIds);
}
}
Dim myPISystems As PISystems = New PISystems()
Dim myPISystem As PISystem = myPISystems.DefaultPISystem
Dim myDB As AFDatabase = myPISystem.Databases.DefaultDatabase
Using search As New AFElementSearch(myDB, "FindElements", )
search.CacheTimeout = TimeSpan.FromMinutes(10)
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.
Version InformationAFSDK
Supported in: 2.10.5
See Also