The allInstancesAtTime operator queries the database's history tables to reconstruct the state of all instances of a specific Class exactly as they existed at a given point in time. It is used for auditing, historical reporting, and comparing past states to current states.
Prerequisites: The Versioned Property
For this operator to work, the MDriven execution engine must be actively recording history for the target class.
- You must select the Class in the MDriven Designer and set its
Versionedproperty toTrue.
Syntax & Parameter Type
A common misconception is that this operator takes a standard DateTime object. It actually requires an Integer
ClassName.allInstancesAtTime(timeStamp : Integer)
To bridge the gap between calendar dates and MDriven's integer timeline, you can use the .timeToTimeStamp converter on your DateTime value.
Examples & Usage
1. Fetching from a Specific Date and Time
Use DateTime.Parse (or DateTime.Create) and immediately convert it to a TimeStamp integer.
Complaint.allInstancesAtTime(DateTime.Parse('2025-01-01 00:00:00').timeToTimeStamp)
2. Fetching Relative to the Current Time
You can calculate a date relative to today (e.g., 30 days ago) and convert that to a TimeStamp.
Complaint.allInstancesAtTime(DateTime.Now.AddDays(-30).timeToTimeStamp)
Common Errors & Troubleshooting
Error: System.DateTime does not conform to System.Int32
- Cause: You passed a
DateTimeobject directly into the operator. - Solution: Append
.timeToTimeStampto your DateTime expression to convert it into the required Integer format.
Error: Specified method is not supported. ,InternalEvaluate()...
- Cause: You are calling
allInstancesAtTimeon a class that does not have history tracking enabled. The EcoSpace cannot execute the temporal query because the history tables do not exist. - Solution: Go to your model, set the Class's
Versionedproperty toTrue, and update your database schema.
See also: allInstances
