After mentioning DynamicModel ORM (a personal project) in previous posts , I would like to write a bit more about this project.

This posts acts as a “note-to-self”, to remember what I did last summer. And secondly, to credit some projects that inspired me or aided development in one way or the other.

Why my own ORM?

DynamicModel is being developed in C# .NET. It’s certainly not the first ORM written for .NET. For those not familiar with the .NET ORM landscape: some currently popular .NET ORM’s: are Entity Framework, NHibernate, LINQ-To-SQL.

Most important reason for starting this project was fun and the learning experience. Secondly, since I am a web developer I work with databases and ORM’s a lot, so it’s nice to work with an ORM that is tailored to my personal needs. Therefore, my ambition is not to build an ORM that performs better than the above mentioned (although that would be nice), or has more features, but an ORM that has all the basic functionality I need, plus features I’d like to have but many other ORM’s miss.


Like most OR mappers, DynamicModel uses entity classes to model database rows. An entity instance represents exactly one row in a database table.

Mapping between database and entity is done using attributes to annotate classes and properties. This approach is much like Castle ActiveRecord‘s and DataObjects.NET (there is no mapping XML).

CRUD operations can be done via the DmContext class in a ‘unit-of-work’-like pattern:

using (DmContext context =
    new DmContext(MySqlConn, DataProvider.MYSQL))
    Album album = _context.Find<Album>(6);
    if (album.Tracks != null)
        foreach (Track track in album.Tracks)

            Console.WriteLine("  Track " + track.Name + ". Price: " + track.UnitPrice);

Besides basic (but must-have) OR mapping functionality such as lazy/eager loading, the “like-to-have” featues I build into DynamicModel are:

  • Currently supports the three databases I work most with:
    • MySQL 5+
    • MS-SQL 2005+
    • PostgreSQL
  • Code generation via T4 templates (experimental). Provides automatic generation of entity classes from a database
  • ODBC support. DynamicModel supports connections to supported database servers via ODBC. I needed ODBC support because some ISP’s only allow connections to their database server via ODBC, and many of the major ORM’s only support native database connections.
  • Data and schema migration API: an API to move data and schema (table and foreign key definitions) between database systems. I build a GUI tool around this API to be able to easly transfer databases between different DBMS’es. Example scenario: export of a MS-SQL database to MySql
  • Versioning/Migrations. Migrations allows database versioning via individual transformations. The general idea of migrations comes from Ruby on Rail migrations. A .NET tool that inspired me is migratordotnet; see this blog post: Database Migrations for .NET. The only major .NET ORMs that also support migrations (to my knowledge) are Lightspeed ORM and SubSonic.

Finally, I’m not a big fan of command line tools, so I build a GUI around my migration API:

The DynamicModel migrator

Development of DynamicModel is an ongoing process. I will share my progress in coming posts.

Read more: other .NET OR mappers :

One Response to “DynamicModel”

  1. Hurrah, that’s what I was exploring for,
    what a stuff! present here at this web site, thanks admin of this website.

Leave a Reply

Human Verification