Saturday, November 3, 2007

Active Record for C#

As I am a fan of Active Record and in the company in which I work C# is used to develop applications I looked for an Active Record implementation for C#. After some searching I found one which is called Castle Active Record. It does exactly what I want namely it provides a framework which makes it possible to use the Active Record pattern with C#.
As I am curious I tried it out imediatly. I did the tutorial provided on the homepage.
I had no problems with the tutorial and initially I tried it with a PostgreSQL database and I was not able to get it work. I always got an error message when I tried to let Active Record create the database schema. After some researches on the internet and some trying out I found out that I had to add a reference for the two files "Npgsql.dll" and "Mono.Security.dll" which are located at "C:\program files\PostgreSQL\8.2\Npgsql\", to my Visual Studio project. After that everything worked fine.
To make it work with MySQL you simply have to download and install the MySQL Connector from here. After you installed it you simply add it to your references and everything should work.

The project showed me how Active Record can be used with C# and I think that it can be very useful also for commercial projects. Give it a try...

I realized that the demo project is only available as VS2003 version. I will make it available as VS2005 version as soon as possible for people who have not time to write the project from scratch ;-) In my version I additionally added a search functionality which automatically iterates over all attributes of an object by using reflection and allows therfore searching in all attributes/columns.

Enjoy

Useful links:
Castle Active Record Home
MySQL Home
PostgreSQL Home

No comments: