DataObjects.NET

DataObjects.Net.png

DataObjects.Net is a persistence and object-relational mapping framework for the Microsoft .NET Framework. It allows to define the business logic (persistent objects) directly in one of the .NET languages like C#. The persistent objects can be retrieved by LINQ queries. Persistent data can be stored in SQL Servers or in even simpler DBMS which only provide simple indexing operations. In CONTRAST to many other ORM frameworks the database model is generated and maintained automatically. It is open source since Version 4 and can be licensed under GPL v3 and proprietary for closed source applications.

Persistence and Mapping

Application developement with DataObjects.Net follows the domain-driven design principle. The model (business logic) can be declared directly and completely in source code using attributes. Even the migration and update logic from older model versions is declared this way. Because the complete model is expressed in standard .NET source code DataObjects.Net integrates seamlessly in revision control and visual class design tools.

This code sample declares a persistent Person class with a Name field:

[HierarchyRoot]
public class Person: Entity
{
  [Field, Key]
  public Guid Id { get; private set; }
 
  [Field(Length = 100)]
  public string Name { get; set; }
}

Unlike NHibernate DataObjects.net doesn't need a declared mapping to some kind of database. Instead it generates the needed tables and columns on the database itself. To do this it uses this metadata (the model) to create and modify the database schema on the underlying SQL Server or other DBMS. This reduces the development time and maintenance effort, but makes it impossible to use existing data in a heterogeneous manner. It is difficult or quite impossible to use it for accessing existing data. Migration of old data STOCK must be done.

The persistent classes can be used like every other class to create and modify persistent objects with the new operator and by assigning same data to properties.

using (domain.OpenSession()) {
  using (var transactionScope = Transaction.Open()) {
 
    var person= new Person() { Name = "John Doe" };
    person.Name = "Jane Doe";
     transactionScope.Complete();
  }

Due to the use of session scopes and transaction scopes these transactional modifications are ACID. Because these persistent classes derive from nothing (have no base class) and don't use methods like session.Save(person) some other mechanism must come into play to store the data. DataObject.Net uses aspect-oriented programming to inject the load/save mechanisms in the classes. The PostSharp framework is used to inject the policies for persistence.

The persistence layer is completely transparent and does performance acceleration like lazy loading and caching behind the scenes.

LINQ Queries

Unlike POCO the DataObjects.Net Entities are queryable in a relational manner. This can be done with a low level API - the so called ‘Record Set Engine Queries’. And it can be done high level with LINQ which is completely supported. Query compilation and optimization is cached, so that multiple execution of the same query won't need to complile the LINQ lambda expressions again.

A simple LINQ query:

using (domain.OpenSession()) {
  using (var transactionScope = Transaction.Open()) {
    var personsNamedJohn = from message in Query<Person>.All where person.Name.StartsWith("John") select person;
 
    foreach (var person in personsNamedJohn )
      Console.WriteLine(person.Name);
 
    transactionScope.Complete();
  }
}

Data Storage

DataObjects.net is designed to work with arbitrary data stores, not only SQL servers. But currently only Microsoft SQL Server, PostgreSQL and a in memory database is available. A own embedded database is planed so that DataObjects.Net can be used without any third party database.

Criticism

DataObjects.net Version 4.x is the successor of the proprietary ORM framework DataObjects 1x - 3x. Users of the old framework are waiting several years for the new version. Since 2009 DataObjects.Net Version 4 is usable in production environments, but not all of the 3x features are available. On the other hand the development team is very active and has released the announced features as published on the roadmap.

See also

  • List of object-relational mapping software
  • NHibernate