views:

342

answers:

1

What is the best way to generate C# classes for use with Castle ActiveRecord and NHibernate given an existing database structure?

Can you recommend any of the class generation tools or is it just less hassle to write the classes by hand?

+2  A: 

If you only have a handful of tables with not many columns, it may be best to write your classes by hand. I wouldn't recommend hand writing many classes though if your database already exists.

Active Writer may meet your needs: http://using.castleproject.org/display/Contrib/ActiveWriter

There are other code generators in various states of usefulness. There are other questions in this vane on StackOverflow. Here are a couple:

http://stackoverflow.com/questions/2042967/net-orm-solution-with-class-auto-generation-subsonic-castle-ar

http://stackoverflow.com/questions/41752/nhibernate-generators

Update June 01, 2010:

I have now publicly released a (T4 based) code generator for Castle ActiveRecord as a Windows application:

http://www.AgilityForORMs.com/Home/Products/

There are both free and commercial versions of the code generator. The free version should work just fine for the majority of "green field" databases that follow certain conventions (for example: using surrogate primary keys).

The AgilityForORMs Castle ActiveRecord code generator has been tested against .NET 3.5 and MS SQL Server 2005/2008. Support for other database vendors, as well as .NET 4.0, is planned.

I wouldn't have written this code generator if I would have found one "off the shelf" that I was happy with. I figured I may as well spend some extra time packaging it up so other people could benefit as well.

Michael Maddox