ORM Basics

Last Updated: 12/05/2015 Introduced in Verision: 2.0
ORM BASE CLASSES
There are three ORM base classes that you can inherit from to create an ORM object. They are as follows.
  • BaseORMEntityWithLogicalDelete – adds logical delete functionality to our ORM class.
  • AbstractEntity – inherits from  BaseORMEntityWithLogicalDelete and adds default fields (like creation date, deletion date, etc), not folder related, is default searchable.
  • AbstractFolderEntity – same as  AbstractEntity, but lives in a portal folder.
 
CREATING AN ORM OBJECT
To begin you will need to write your own ORM type. To do so, you will need to write a class and do the following:
  1. Decorate your class with  [ORMEntity("name_of_your_type")]. This will mark your class as an ORM entity and allow you to name the DB table that is generated to hold the data you save of this class.
  2. So that your class will utilize some of the common entity properties (like creation date, deletion date, etc). your class should inherit from  DecisionsFramework.ServiceLayer.AbstractEntity.
  3. If you want to use your ORM class in Decisions steps, also decorate it with the following two attributes:  [DataContract] and  [Writable].
The first property of your class should be decorated with  [ORMPrimaryKeyField] (and if you are planning to use this type in steps, it is also a good idea to decorate with  [PropertyHidden]). 
All other properties of your class should be decorated with  [ORMField]. The  [ORMField] attribute has many overrides which will allow you to set the DB type, the field name, and other specifications. The most common will be to override the field name. For example, to set a field name of “full_name” your attribute would look like this:  [ORMField("full_name")] 
 
Below is an example showing a full ORM class.

 

Once you have created an ORM object you can interact with those ORM entities using DynamicORM object. To do so create a new instance of ORM. Off that object you will find any methods like Fetch, Store, Exists and Delete. Example code for these methods is shown below.

RELATIONSHIPS

Using the ORM, you can also create objects that have relationships of one-to-one, one-to-many, and many-to-many. You do this by specifying the desired relationship on your field.
 
Below is an example property on an ORM object that specifies a field of another ORM type with a one-to-many relationship type. The property  _PersonList is an array on our ORM object. When creating the new ORMOneToManyRelationship object we specify a field name of  "_SampleOrmWithRelationship". This is add a _SampleOrmWithRelationship field to the  sample_orm_entity_person database table which will contain the id of the  SampleOrmWithRelationship object to which it is related.

Here is an example of the full ORM object on which we specify the one-to-many relationship of  _PersonList.

 

Additional Resources