LINQ Support
PPJ exposes enumeration for SalArray<T>, SalTableWindow, and SalFormTableWindow, allowing C# LINQ queries over application data. Add using System.Linq; for LINQ extension methods.
Arrays
For an array of customer objects with an Active member:
SalArray<CCustomer> customers = new SalArray<CCustomer>();
// Populate customers before enumerating the query.
var activeCustomers = from customer in customers
where customer != null && customer.Active == true
select customer;
Use == to compare; = assigns a value. Most LINQ queries execute when enumerated, not when declared. Use ToList() when a snapshot of the selected objects is needed. This copies references, not the objects themselves. See Microsoft's introduction to LINQ queries.
TableWindow Controls
Table enumeration yields SalTableRow objects. For a numeric column storing 1 for active:
var activeCustomers = from row in tblCustomers
where row[tblCustomers.colActive].Number == 1
select row;
A column can also be selected by name, such as row["colActive"]. Use column references where possible so a rename can be caught at compilation. Match the cell accessor to the column's data type.
Scope and Performance
These queries operate over in-memory array or table rows. They do not translate into SQL or fetch additional database rows. Apply database filtering in SQL when a large result set can be reduced before loading it. Enumerate visual controls in their UI/session context and avoid changing the table structure during enumeration.
A Deferred Query Is Not a Saved Result
Declaring activeCustomers saves the query, not its current matches. If a customer's Active value changes before enumeration, the later query can select a different set. Enumerating it twice can also observe two different states.
activeCustomers.ToList() materializes the matches at that moment. It does not clone customer objects or detach table rows from their control. A report or background job needing a stable independent snapshot should copy the required field values into its own data objects while it is safe to read the source.