Loading Top Level Objects
- Last UpdatedJan 12, 2026
- 2 minute read
- PI System
- AF SDK 3.2.0
- Developer
In AF, SDK objects which can be checked-in, are considered top-level objects. These items can be loaded individually from the server or in bulk. Typically, when these items are first returned to the client application from a search or from accessing a collection, only the header information is returned. When your program accesses information that is not in the header, then the AF SDK will retrieve the full object definition from the server. If an application does this with many objects, many RPCs may result. This example uses the AFElementSearchFindElements method to illustrate a mechanism for bulk loading a list of objects into the client. This same mechanism can be used to bulk load top-level objects using one of the searches derived from the OSIsoft.AF.SearchAFSearch class
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') that have a 'Valve' category. 12int count; 13using (var search = new AFElementSearch(myDB, "FindValves", @"Root:'WestPlant\Area32' Category:'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}