---
title: "Using Simple ORM Objects"
slug: "using-simple-orm-objects"
description: "This document shows how to use simple ORM objects in the SDK.  The document provides examples for how to fetch an object by ID, fetch an object with where conditions, store an object, save select fields of an object, check to see if an entity exists, and how to get a count of ORM objects."
updated: 2024-11-19T22:00:58Z
published: 2024-11-19T22:00:58Z
---

> ## Documentation Index
> Fetch the complete documentation index at: https://documentation.decisions.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using Simple ORM Objects

## 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](https://documentation.decisions.com/docs/orm-basics).[MyCustomer.cs](https://cdn.document360.io/6ef8bcc1-6489-4486-9ad1-83acff7e5df0/Images/Documentation/MyCustomer.cs)

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

```csharp
ORM<MyCustomer> orm = new ORM<MyCustomer>();
MyCustomer mc= orm.Fetch("11223");
```

#### DynamicORM

```csharp
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**

```csharp
ORM<MyCustomer> orm = new ORM<MyCustomer>();
MyCustomer mc = orm.Fetch("11223");
```

---

### **Fetching an object with where conditions**

```csharp
ORM<MyCustomer> orm = new ORM<MyCustomer>();
MyCustomer[] mc = orm.Fetch(new WhereCondition[] {new FieldWhereCondition("first name", QueryMatchType.StartsWith, "J"), });
```

---

### **Storing an object**

```csharp
ORM<MyCustomer> orm = new ORM<MyCustomer>();
orm.Store(new MyCustomer() {FirstName = "Joe"});
```

### **Storing multiple objects**

A list can be stored using the Store() method.

```csharp
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.

```csharp
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**

```csharp
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****

```csharp
ORM<MyCustomer> orm = new ORM<MyCustomer>();
if (orm.Exists("12234"))
{
   // do something
}
```

---

### ****Getting a count of entities****

```csharp
ORM<MyCustomer> orm = new ORM<MyCustomer>();
long count = orm.GetCount();
```
