Wednesday, 17 October 2007

ActiveWriter for NHibernate

Like NHibernateAddin, ActiveWriter is an add-in for Visual Studio 2005.

It leverages the DSL functionality to allow you to model classes and relationships and it generates the NHibernate mapping and class files (in VB or C#).

I think this has the potential to meet all my requirements for doing the hard work of class and mapping generation.

Gökhan (the main developer) has done a great job, though his focus is more on C#, so I've submitted some bugs (and worked on some patches) to improve the VB side of things.

One thing that is missing at the moment, is that if you drop tables onto the design surface one at a time, they don't automatically add relations with existing classes. I did discover yesterday that if you drop multiple tables at the same time, it does figure out the relations and add them in.

One of my patches adds support to clean up the class property names. If your database naming strategy means that your column names have some kind of common prefix, you probably don't want that in the property name.

For example, given the following database table:

CREATE TABLE [dbo].[TEST_CONTENT]
( 
 [TC_ID] [int] IDENTITY(1,1) NOT NULL, 
 [TC_TEST] [int] NOT NULL, 
 [TC_CONTENT] [int] NOT NULL
) 
If you set the model's "Property Name Filter Expression" property to the regular expression ^\w+?_ it will then remove the text up to the first underscore for each property name, so that you end up with a class like this:

TestContent Class Diagram

Future improvements

  • Add relations when dropping additional tables
  • Support for custom types for properties
  • Auto-arrange model layout

1 comment:

Gökhan said...

- Add relations when dropping additional tables

There's a TODO somewhere in the code for this :) Might be a problem if previously added entites have changed before the second drag, or if there are some hand made entities with the same name.

- Support for custom types for properties

Does this help?
http://support.castleproject.org/browse/CONTRIB-28

- Auto-arrange model layout

Tried. Too hard. DSL Tools also supposed to do this automatically but didn't when I called layout method.

Thanks again for all the patches.