Using Simple ORM Objects
- 09 Nov 2020
- 1 Minute to read
- Print
- DarkLight
This documentation version is deprecated, please click here for the latest version.
Using Simple ORM Objects
- Updated on 09 Nov 2020
- 1 Minute to read
- Print
- DarkLight
Article summary
Did you find this summary helpful?
Thank you for your feedback
Overview
This article goes over two ORM Objects and their uses. This is for SDK developers to work with the ORM, Decisions' feature for storing and retrieving entities in the main Decisions database. Review the SDK Overview document to learn what the Decisions SDK offers.
This example uses a basic "MyCustomer" class available to download below. Please review the ORM Basics document for information on creating an ORM, ORM Base Classes, and ORM Objects.
Typesafe vs. non-typesafe ORM accessors
Two classes represent access to ORM storage.
- ORM
- DynamicORM
The difference between these classes is the generic one adds several typesafe methods. Below is an example of both of these.
ORM
ORM<MyCustomer> orm = new ORM<MyCustomer>();
MyCustomer mc= orm.Fetch("11223");
DynamicORM
DynamicORM orm = new DynamicORM();
IORMEntity e = orm.Fetch(typeof (MyCustomer), "11223");
MyCustomer mc = (MyCustomer) e;
Example
For the sake of this article, ORM will be used for the examples.
Fetching an object by ID
ORM<MyCustomer> orm = new ORM<MyCustomer>();
MyCustomer mc = orm.Fetch("11223");
Fetching an object with where conditions
ORM<MyCustomer> orm = new ORM<MyCustomer>();
MyCustomer[] mc = orm.Fetch(new WhereCondition[] {new FieldWhereCondition("first name", QueryMatchType.StartsWith, "J"), });
Storing an object
ORM<MyCustomer> orm = new ORM<MyCustomer>();
orm.Store(new MyCustomer() {FirstName = "Joe"});
Storing multiple objects
A list can be stored using the 'store' method on ORM.
ORM<MyCustomerAccount> orm = new ORM<MyCustomerAccount>();
orm.Store(new MyCustomer[]
{
new MyCustomer() {FirstName = "Joe"},
new MyCustomer() {FirstName = "John"}
});
A much more efficient (using batch insert mechanism in DB) is also available.
ORM<MyCustomer> orm = new ORM<MyCustomer>();
orm.BatchInsert(new MyCustomer[]
{
new MyCustomer() {FirstName = "Joe"}
new MyCustomer() {FirstName = "John"}
});
Saving only specific fields on an object
ORM<MyCustomer> orm = new ORM<MyCustomer>();
orm.Store(new MyCustomer() {FirstName = "Joe"}, false, false, "first_name", "last_name");
The extra parameters are:
- Store relationships
- Process before and after save methods
- Fields to save
Seeing if an entity exists
ORM<MyCustomer> orm = new ORM<MyCustomer>();
if (orm.Exists("12234"))
{
// do something
}
Getting a count of entities
ORM<MyCustomer> orm = new ORM<MyCustomer>();
long count = orm.GetCount();
Was this article helpful?