Bundt Programmer's Guide · Bundt Programmer's Interface version 1.0.1.0

Query Instance Model for Objects

The following example shows how to query an instance model to retrieve selected collections of objects.

To execute this code, you will need a reference to the ModellingEngine library.

using Incipit.Bundt.ModellingEngine;

//load an instance model.
var imo = new FileModelPersister("C:\\Temp\\MyModel.bundt-im").LoadInstanceModel();

//get the 10 most recent buildings that are over 40 metres tall.
var obsTallBuildings = imo.GetObjectsOfClass("Building")
    .FilterOnValue("Height", va => va.ContentNumber > 40)
    .SortOnValueDescending("ConstructionYear")
    .Take(10);

//get object for the city of Paris.
var obParis = imo.FindObject("paris");

//get buildings in Paris with no status information.
var obsBuildingsInParis = imo.GetObjectsOfClass("Building")
    .FilterOnReference("Location", rf => rf.Opposite == obParis)
    .FilterOnValueSet("Status", vast => vast.IsNull);

In line 4, we load an instance model. For the sake of this example, we will assume that this model contains many objects of types City and Building, and that buildings have data for Height, ConstructionYear and Status. In addition, buildings are related to cities via an association with role Location.

In lines 7-10, we query the model for the 10 most recent buildings that are over 40 metres tall. To do this, we first retrieve all objects of type Building by calling GetObjectsOfClass. Then we select those objects having a Height over 40 by calling FilterOnValue. Then, we sort the resulting objects by ConstructionYear descending by calling SortOnValueDescending. Finally, we take the first 10 objects. Note how Filter* and Sort* methods can be stringed together to compose queries of arbitrary complexity. Also, they can be mixed and matched with standard methods operating on collection such as Take or Skip.

In line 13, we pick a specific object by its identifier by calling FindObject.

Finally, in lines 16-18 we query the model for those buildings in Paris having no status information. To do this, we first retrieve all objects of type Building by calling GetObjectsOfClass, like we did before. Then we select those objects having a Location reference to the Paris object by calling FilterOnReference. Finally, we pick those objects with a null value set for Status by calling FilterOnValueSet.


Contents distributed under a Creative Commons Attribution 4.0 International License · About · Terms of Use · Contact Us · last updated on 08 October 2020