Click or drag to resize

Welcome

The ObjectDb library implements a lightweight in-process database for storing and retrieving class objects and their property values from a local high-performance database.

Overview

The ObjectDb library is designed to be as easy to use as possible, with a small footprint and trivial dependencies. The backing storage is the Microsoft Extensible Storage Engine (ESENT) high-performance, high-capacity, transactional database which is built into all modern versions of Windows. The ObjectDb runtime is distributable as two small managed libraries which can be added as project references. You can also reference the Nuget package Orthogonal.ObjectDb.Esent. The following sample code shows how simple it is to add powerful database support with very little code.

C#
using Orthogonal.ObjectDb.Esent;
:
// Open or create the database.
var db = ObjectDb.Create(@"C:\testing\Sample Database");
// Insert a new employee. The sample class has an Int32 Id
// property which acts as the auto-increment primary key.
var emp = new Employee("Smith", "John", "London, UK");
db.Insert(emp);
// List all employees.
foreach (emp in db.List<Employee>())
{
  Trace($"Employee Id {emp.Id} {emp.First} {emp.Surname} lives in {emp.Address}");
}
// Get an employee by primary key Id.
emp = db.Get<Employee>(6604);
:
db.Dispose();

The library's API is small and consists of methods with obvious names like Insert, Get, Delete, List, Update, Save, etc. There are only 9 core methods and 5 utility helper methods.

When a class object is inserted into the database, the values of all public properties that are both readable and writable are extracted and stored. One or more class object properties must be specified as the primary key to uniquely identify database records.

ObjectDb does not behave like a relational database and has no concept of a schema or relationships. It does have other interesting and useful features that makes it more like a NoSQL database. Because there is no concept of a schema for the database contents, an inhomogeneous set of class objects can be saved in the same database. It's also possible to efficiently seek and list on any stored property name and an index over that property will be created on first use.

The underlying ESENT database can be up to 14TB in total size and rows can efficiently contain text or binary blobs up to 2GB in size. The ObjectDb library only uses the ESENT API functions related to indexing, effectively using the database in the style of a classical multiple-index ISAM file. The Wikipedia article on ESENT describes many of the more advanced and custom features of the database, which are not needed or used by the ObjectDb library.

For more information, including sample code, visit the Azure DevOps repository.

History

Author's Note...

Many times over the last decade I've wished I had a simple database for storing objects and their property values. My wish includes the following conditions for such a database: all managed code; in-process; simple public API; no installation; add-a-reference and go; no complicated dependencies; transactions not needed; no configuration.

In June 2013 I asked in the ozdotnet mailing list if anyone knew of such a database. I examined over a dozen resulting suggestions but found them all to be licensed, over-engineered, or they broke most of my wish conditions. I therefore reluctantly decided to create my own simple database that satisfied my wish conditions.

ObjectDb does not attempt to compete with the features of sophisticated NoSQL or document databases like mongoDB, RavenDB and many other such products, but it does share a lightweight and useful subset of their behaviour. It is interesting to note that RavenDb originally used an ESENT database as its backing storage.