ORM Done Right. At Last.
The one you always wanted, but never had. Until now.
What is ORM?
"Object-relational mapping (ORM) ... is a programming technique for converting data between incompatible type systems in object-oriented programming languages" - (Wikipedia).
Most often the term is used for software that "maps" the data in relational database to objects inside an application written in some OOP language like c#. In short, ORM either generates code for or works by itself as a Data Access Layer in your application, saving you the time and effort of writing it by hand. For example, LINQ-2-SQL and MS Entity Framework are ORM tools.
VITA Highlights
- Entities are defined as .NET interfaces - minimum coding required. Implementation classes are created at runtime using IL code generation.
- Entities are self-tracking - they maintain original and modified property values, automatically register for update.
- Database model is automatically created/updated from entity model. Existing data is preserved. Database schema follows c# code.
- Database keys and indexes are defined through entity attributes in c# - you can define most of the database artifacts in c# code, including custom stored procedures using LINQ syntax.
- Automatically generated CRUD stored procedures. Alternatively, application can use direct SQL queries.
- Support for one-to-many and many-to-many relationships. Foreign keys are automatically inferred from c# entity references.
- Automatic sequencing of update operations to satisfy referential constraints.
- Full support for identity columns and auto-generated GUIDs
- Computed columns.
- Automatic validation on submit. You can define a custom validation method for an entity - it will be automatically invoked before submitting changes to database.
- Full LINQ support: you can run direct LINQ queries against entities.
- Custom Stored Procedures - you can define custom stored procedures for SELECT, INSERT, UPDATE, DELETE operations in pure c# code, using LINQ syntax. The code will be compiled into stored procedures in database.
- Top Performance - LINQ queries are compiled at startup into stored procedures. On the object/c# side, values storage in entities is organized as arrays and accessed by index, not by column name. Data readers are accessed by column index, not by column name.
- Companion types - you can define database artifacts like keys and indexes through attributes on separate types called companions. This way you can put database artifact definitions in a separate c# file and let your database expert maintain it without clashing with other developers.
- Component Packaging Technology - for the first time, we have a way to pack a set of entities/tables with the surrounding code into a self-contained component - data module. Data modules can cover specific areas of functionality, can be independently developed, tested and distributed, just like Windows Controls libraries. The application is then assembled from independent modules, each covering specific part of functionality. More details here.
- Compact, concise, reasonable-size codebase - not a monster like many other ORMs. You can browse through the entire codebase in a matter of an hour - only 70 c# files, less that 150 classes.
- Did I mention - supports enums?
Why New ORM?
It seems like we already have
too many. So why another one? Very simply, because none existing is good enough. In every one I tried, I always find something missing, even if the overall architecture and design concepts are done well. Unfortunately, in all cases the missing parts are critical, and without them ORM is not a fit for the applications I built. I always dreamed and waited for an ORM that would finally do everything right, but it never came. Finally I decided to build one myself - the one I always wanted. And I am sure that's the one you always wanted too!
That said, VITA is not completely new in every aspect. Many elements and concepts I used you may find in existing solutions. But there are a few critical points that really make VITA stand out, in addition to all the highlighted features I listed above - read more
here.
Quick Start
Look at the
demo application listing to see the capabilities of VITA framework. Read the
Component Packaging Demo Page for more information on how to package your code into independent reusable components.
System Requirements and Supported Platforms
.NET 4.0, Visual Studio 2010 SP1. Developed and tested on Windows 7, 32-bit; database server -
MS SQL Server 2008 R2, should run OK with SQL Express.
The framework uses LINQ-2-SQL for query execution and compilation to stored procedures.
Unfortunately LINQ-2-SQL coming with .NET framework supports MS SQL Server only. Projects like
DbLink or
LinqConnect may help with support for other servers.
The functionality related to data access specifics is isolated in DbDriver class, which should be sub-classed for particular server. The project contains one such sub-class for MS SQL Server.
Download the code
Download zip on the
Download page contains the full source code, demo console application, and unit test projects for VS Test system and NUnit. Read the
Demo-Running Instructions before running the code.
The Long Long Long Road Ahead
Once the basic missing pieces are in place, I plan to deliver more advanced features, like:
- Support for special data types/columns like timestamps and row versions.
- Batched updates
- Partial selects and partial updates - updating only those fields that actually changed
- Denormalization support
and some other features. After that, the plan is to use VITA's component packaging technology to create a set of reusable modules with functionality that is present in almost every appliation: Login, Authorization, Audit, Locking, ExceptionHandling and logging, tracing, session management. We can then move to more specialized modules like Party/People module, Addresses, financial accounts and transactions, etc.
We are at the beginning of the very long long long road. This is the first step on our long way to fix the seriously troubled world of business applications development. It will be a long and exciting journey - let's start going!
Additional Links