Using Simple ORM Objects
- 19 Nov 2024
- 1 Minute to read
- Print
- DarkLight
Using Simple ORM Objects
- Updated on 19 Nov 2024
- 1 Minute to read
- Print
- DarkLight
Article summary
Did you find this summary helpful?
Thank you for your feedback
Overview
The Decisions SDK allows developers to work with the ORM, a feature for storing and retrieving entities in the main Decisions database.
This example uses a MyCustomer class that is available to download below. For more information on creating ORM, the ORM Base Classes, and Objects, review ORM Basics.
The ORM class and DynamicORM class represent access to ORM storage. The difference is that the ORM class adds multiple typesafe methods. Below is an example of each class.
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
The examples below use the ORM class.
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.
ORM<MyCustomerAccount> orm = new ORM<MyCustomerAccount>();
orm.Store(new MyCustomer[]
{
new MyCustomer() {FirstName = "Joe"},
new MyCustomer() {FirstName = "John"}
});
A list can also be stored using the BatchInsert() method.
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");
Other parameters can be used, including store relationships, process before and after save methods, and 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?