SubSonic v1 (ActionPack) vs dOOdads vs Castle ActiveRecord
Posted
Mon, May 7 2007 4:05 PM
by
Mischa Kroon
SubSonic Vs dOOdads Vs ActiveRecord
Let's meet our contenders:
dOOdads
An ORM framework which was provided by the people who also gave us MyGeneration.
It's built with a couple of things in mind:
- Ease of use
- Supporting a large amount of DBMS systems
Summary
MyGeneration presents dOOdads, an elegant .NET architecture available in C# and VB.NET and capable of supporting any .NET managed data provider. Currently dOOdads are available for Microsoft SQL, Oracle, Firebird, Access, PostgreSQL, VistaDB, SQLite, and MySQL.
Castle's ActiveRecord
ActiveRecord is the DAL which is supplied with the Castle project.
Summary
The Castle ActiveRecord project is an implementation of the ActiveRecord pattern for .NET. The ActiveRecord pattern consists on instance properties representing a record in the database, instance methods acting on that specific record and static methods acting on all records.
Castle ActiveRecord is built on top of NHibernate, but its attribute-based mapping free the developer of writing XML for database-to-object mapping, which is needed when using NHibernate directly.
SubSonic
The first public DAL which employed Build Providers that I know off :)
Summary
A Data Access Layer (DAL) builder that requires no code on your part, it builds itself at compile-time with a full object layer and strongly-typed Collections
A complete utility toolset, complete with Rails-like scaffolding, migrations (DB Versioning), and code generators
A dynamic query tool, that lets you use SQL Server and the Enterprise Library without having to know SQL
An OR Mapper that extends to views and stored procedures so you're not locked into the OR/M thing
The syntax / setup by ORM:
Setup dOOdads:
Install MyGeneration code generator Create stored procedures ( optrional ), Create DAL.
Copy files to current project folder.
Copy DLL and your done.
Setting the connectionstring can be done in the appsettings: "dbconnection" is it's default.
Setup Active Record:
Generate Classes using Active Record Generator (Sql Server only), or through several other methods. Generating the classes is pretty wrist friendly.
Just setting property's for every column and defining it's relationship is enough. b
It also needs a section in the web.config or a bit of code to set it up and a couple of DLL's
Setup SubSonic:
Classes can be generated by using a build provider, which means as much as have let VS.Net create the classes at build time which means you don't have to manually have to update the classes. ( Needs full trust )
Classes can also be generated trough the supplied templates which are called through a web interface.
It also needs a section in the web.config or a bit of code to set it up and a single DLL.
Setup Conclusion:
All have different approaches with none of them actually having a leg up on the others at least not for me.
They can all be set up within 10 - 20 minutes and are thus also usable for small projects.
-----
The Code for some standard actions:
In this table the code for the active record solutions is missing this is because I couldn't really find any documentation in a downloadable form for this framework on how to do these things. (which doesn't mean that it's not out there :)
| dOOdads |
Active Record |
SubSonic |
|
Retrieving all records of a table |
Dim emps As New Employees emps.LoadAll |
|
Employees.FetchAll(); or sorted: GridView1.DataSource = Employees.FetchAll(SubSonic.OrderBy.Asc(Employees.Columns.LastName)); or in a collection: EmployeesCollection products = new ProductCollection(); Employees.OrderByAsc(Employees.Columns.LastName); Employees.Load();
|
| Retrieving a single record |
Dim emps As New Employees emps.LoadByPrimaryKey(EmpID) |
|
Employees employees = new Employees(id); or: Employees employees = Employees.FetchByID(id); or: Employees employees = new Product(Product.Columns.LastName, "Chai");
|
| Adding a record |
| Dim emps As New Employees
emps.AddNew() emps.LastName = "Smith" emps.HireDate = Now emps.Save()
'return new key value EmpID = emps.ID |
|
Dim emps As New Employees
emps.LastName = "Smith" emps.HireDate = Now emps.Save()
'return new key value EmpID = emps.EM_ID
|
| Editing a record |
|
Dim emps As New Employees
emps.LoadByPrimaryKey(EmpID) emps.LastName = "Smith" emps.HireDate = Now emps.Save()
|
|
Dim emps As New Employees (key value)
emps.LastName = "Smith" emps.HireDate = Now emps.Save()
|
| Deleting a record |
|
Dim emps As New Employees
emps.LoadByPrimaryKey(EmpID) emps.MarkAsDeleted() emps.Save()
|
|
Employees.Destroy(key value) |
| More complex query: select top 10 firstname, lastname from employees where salary > 1000 order by lastname asc |
|
Dim emps As New Employees
With emps
.Query.Top = 10 .Query.AddResultColumn(.ColumnNames.firstname) .Query.AddResultColumn(.ColumnNames.lastname) .Where.salary.Value = "1000" .Where.salary.Operator = WhereParameter.Operand.GreaterThan .Query.AddOrderBy(.ColumnNames.lastname, WhereParameter.Dir.DESC)
End With
emps.Load() GridView1.DataSource = emps.defaultview
|
|
dim q as New SubSonic.Query(Employees.TableName)
q.top = "10" q.SelectList = Employees.Columns.firstname + ", " + Employees.Columns.lastname q.AddWhere(employees.Columns.salary, SubSonic.Comparison.GreaterThan, 1000); q.OrderBy = SubSonic.OrderBy.Asc(Employees.Columns.lastname)
GridView1.DataSource = q.ExecuteReader()
|
Strengths / Weaknesses:
dOOdads
The good:
- has been around for a while
- has support for a large amount of databases
- has super easy aliassing built into it through the user of MyGeneration
- source in C# and VB.Net
- simplest framework of the lot (even I understood some of it :P)
- active support forum
- has a silly name :)
The bad:
- no active development at this time
- no templates support for dynamic SQL from MyGeneration itself
Subsonic
The good:
- least amount of code to do stuff
- build providers can mean: almost zero todo to get it working
- very rapid development of the framework
- free helpers:
- auditing (created by, created on, modified by, modified when)
- scaffolding (control using subsonic)
- html report of tables
- it feels "smart"
The bad:
- it hasn't been around for very long
- very rapid development of the framework
- bombs on database tables with spaces in them amongst other things.
Castle Active Record
The good:
- it's built around the NHibernate engine
- it has support for the Hibernate query language
- it has a built in validation framework
- tables can be created from the classes
- it has support for joins
The bad:
- it's built around the NHibernate engine
- it's a probably a lot more complex then the other 2
Conclusion
I myself have used dOOdads with a number of projects and was very pleased with it's performance and it's easy of use and speed to set up.
For another project I used SubSonic and I was even more pleased with it's syntax + being able to use asp.net pages to generate te classes was a big plus for me.
Allthough it's possible to generate dOOdads classes through the command line I never got that far into MyGeneration to pull that off.
For me I'll be going for SubSonic for my future projects.
With dOOdads as a backup ORM.
PS. If anyone has a very easy to set up ORM which he / she thinks is better then the ones in this comparison please let me know :)