AFSearch(T).FindObjects Method
- Last UpdatedJan 12, 2026
- 5 minute read
- PI System
- AF SDK 3.2.0
- Developer
This method will return the objects that match the
search tokens.
Namespace: OSIsoft.AF.Search
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.2.0.7
Syntax
public IEnumerable<T> FindObjects( int startIndex = 0, bool fullLoad = false, int pageSize = 0 )
Public Function FindObjects ( Optional startIndex As Integer = 0, Optional fullLoad As Boolean = false, Optional pageSize As Integer = 0 ) As IEnumerable(Of T) Dim instance As AFSearch Dim startIndex As Integer Dim fullLoad As Boolean Dim pageSize As Integer Dim returnValue As IEnumerable(Of T) returnValue = instance.FindObjects(startIndex, fullLoad, pageSize)
public: virtual IEnumerable<T>^ FindObjects( int startIndex = 0, bool fullLoad = false, int pageSize = 0 ) sealed
abstract FindObjects : ?startIndex : int * ?fullLoad : bool * ?pageSize : int (* Defaults: let _startIndex = defaultArg startIndex 0 let _fullLoad = defaultArg fullLoad false let _pageSize = defaultArg pageSize 0 *) -> IEnumerable<'T> override FindObjects : ?startIndex : int * ?fullLoad : bool * ?pageSize : int (* Defaults: let _startIndex = defaultArg startIndex 0 let _fullLoad = defaultArg fullLoad false let _pageSize = defaultArg pageSize 0 *) -> IEnumerable<'T>
Parameters
- startIndex (Optional)
- Type: SystemInt32
The starting index (zero based) of the items to be returned. - fullLoad (Optional)
- Type: SystemBoolean
If , then the returned objects will be full loaded. If , then the returned objects may not be fully loaded and will require another call to the server if additional information about the object is requested that is not already loaded. - pageSize (Optional)
- Type: SystemInt32
The page size used for retrieving objects from the server. If this parameter is less than or equal to zero, then the page size will be set to the current value of the CollectionPageSize setting.
Return Value
Type: IEnumerableTReturns an enumerable list of the objects found using the search tokens for this search object.
Implements
IAFSearchTFindObjects(Int32, Boolean, Int32)
Exceptions
| Exception | Condition |
|---|---|
| FormatException | This exception is thrown if the ThrowOnError property is and there is a format error in the search query. |
| NotSupportedException | This exception is thrown if the ThrowOnError property is and one of the filters is not supported or the query is too complex to be evaluated by the server. |
Remarks
This method will search for matching objects based upon the search tokens.
By default, attribute values with a data reference are evaluated using the QueryDate of the database.
The TimeContext search filter can be used to modify this behavior.
Examples
1// Get the Database 2PISystems myPISystems = new PISystems(); 3PISystem myPISystem = myPISystems.DefaultPISystem; 4if (myPISystem == null) 5 throw new InvalidOperationException("Default PISystem was not found."); 6AFDatabase myDB = myPISystem.Databases[dbName]; 7if (myDB == null) 8 throw new InvalidOperationException("Database was not found."); 9 10// Create a search to find all the elements in a specific area 11// of a plant (e.g. 'WestPlant\Area32') and have either a 'Valve' category or a name beginning with 'Valve'. 12int count; 13using (var search = new AFElementSearch(myDB, "FindValves", @"Root:'WestPlant\Area32' (Category:'Valve' OR Name:Valve*)")) 14{ 15 search.CacheTimeout = TimeSpan.FromMinutes(10); 16 17 // When the elements are returned from a find operation, they are only 18 // partially loaded into memory, typically enough to display their 19 // inherent properties, such as Name, Description, Template, Type, etc. 20 // When a piece of information is accessed in the element that requires more 21 // information, an RPC to the server is made to fully load the element. 22 // By having the search do a full load, all information is loaded in bulk and 23 // we can reduce the number of RPCs made to retrieve this information. 24 count = search.GetTotalCount(); 25 Console.WriteLine("Found {0} Elements.", count); 26 foreach (AFElement item in search.FindObjects(fullLoad: true)) 27 { 28 // Now we can use the elements without having to make any additional RPCs 29 // In the example below, accessing the Attributes collection would have 30 // caused an additional RPC per element found. 31 // Now we can use the elements without having to make any additional RPCs 32 // In the example below, accessing the Attributes collection would have 33 // caused an additional RPC per element found. 34 Console.WriteLine(" Element {0} has {1} Attributes", item.Name, item.Attributes.Count); 35 } 36}