Accessing Database Instances
The JoobContext class provides methods to access database objects from a specified class.
| Method | Returns … |
|---|---|
| FirstInstance<T> | The first instance of a class |
| FindInstance<T> | An object with the specified OID |
| LastInstance<T> | The last instance of a class |
| AllInstances<T> | All instances of a class |
The following typical sequence of C# calls returns the first instance of the Company class, iterates through a collection on the class, and uses references and methods of the objects in the collection.
JoobContext context = new JoobContext(); Company company = context.FirstInstance<Company>();
If you know the object identifier (OID) of a JADE database object, you can obtain a reference to that object in your C# code, as shown in the following example.
JoobContext context = new JoobContext(); ObjectId oid = new ObjectId(3272, 1); Agent comp = context.FindInstance<Agent>(oid);
In the following example, a virtual collection of instances of the Stock class is iterated.
JoobContext context = new JoobContext();
foreach (Agent agent in context.AllInstances<>(Agent))
{
// process agent
}
