Using OQL

In order to get objects and object-sets in NObject O/R Mapping persistence layer, you can query by using OQL (Object Query Language) that based on native language.

l    Using OQL conditional expression query to get object is as follows:

Customer c = Customer.GetByCriteria(om,

    OQL.Criteria(NW.Customer.CustomerID).EQ("ALFKI")

  );

// ...

or

Customer c = Customer.GetByCriteria(om,

    NW.Customer.CustomerID == "ALFKI"

  );

// ...

l    The conditional expression above can be complex at will as follows:

SelectQuery selectQuery = OQL

  .Select(NW.Order.CustomerID)

  .From(NW.Order)

  .Where(NW.Order.ShipCity == "Macrobject City");

 

Customer c = Customer.GetByCriteria(om,

    NW.Customer.CustomerID.In(selectQuery)

  );

Or:

Customer c = Customer.GetByCriteria(om,

    NW.Customer.CustomerID.In(OQL

      .Select(NW.Order.CustomerID)

      .From(NW.Order)

      .Where(NW.Order.ShipCity == "Macrobject City")

    )

  );

l    The way to get object-set is similar, a sample is as follows:

ObjectSet customers = om.GetObjectSet(NW.Customer,

    NW.Customer.CustomerID.In(OQL

      .Select(NW.Order.CustomerID)

      .From(NW.Order)

      .Where(NW.Order.ShipCity == "Macrobject City")

    )

  );

// ...

Related Topics

Return Existing Object and Object-set