Search code examples
.netnhibernatesubsonicormcastle-activerecord

.NET ORM solution with class auto-generation: Subsonic, Castle AR, ...?


I used to work with a custom data mapping library, and curently I'm trying to switch to a more widespread ORM solution.

After some experimentation, I refined my requirements to the following:

  • able to generate usable classes from database schema (SQL Server support is enough),
  • support for ActiveRecord pattern,
  • programmaticaly configurable (via code or attributes, no HBM files),
  • free.

Could you please recommend one?


So far I have tried:

Subsonic 3.0

The one I currently like most, as it feels like a good balance between functionality and simplicity.

What I don't like:

  • uses IQueryable<> and plural names for both ends of one-to-many relationship - that seems rather counter-intuitive to me;
  • generates one file for all classes - like a thousand lines per class, I have a bad feeling about code files being that large;
  • T4 processing is invoked automatically, so a database with up-to-date schema must be available all the time.

Castle ActiveRecord

CastleAR with ActiveWriter add-in is almost what I need, but ActiveWriter's code isn't perfect (it seems, Nullable<> properties are not supported, and default one-to-many implementation doesn't work) and I couldn't find how to fix this code manually.

Darkside GeneratorStudio produces better code - correct definitions, one file per entity - though it uses cryptic names like RefclassIdRefclass. Personally I like Studio addin more than standalone app, but this certainly is a minor issue.

There're about twenty files bundled in the CastleAR distribution; though not a problem by itself, it feels like overweight. Won't I need too much esoteric knowledge about NHibernate and other stuff?

Fluent NHibernate

Widely recommended, but I wasn't able to find a code generator for it.

Have I missed something important?


Solution

  • A few thoughts on the things you don't like about SubSonic:

    • uses IQueryable<> and plural names for both ends of one-to-many relationship - that seems rather counter-intuitive to me;

    True, I agree this is very counter intuitive and I've never got to the bottom of why it is that way, but you can pretty easily modify the templates to fix this.

    • generates one file for all classes - like a thousand lines per class, I have a bad feeling about code files being that large;

    You'd think this might cause problems but I've yet to come across any and I've yet to see one reported on stackoverflow.

    • T4 processing is invoked automatically, so a database with up-to-date schema must be available all the time.

    It's only invoked automatically if you edit the t4 files so really you only need an up-to-date schema available when you're making changes to the templates.