开发者

How to Generate Castle ActiveRecord C# Classes for an Existing Database

开发者 https://www.devze.com 2022-12-21 06:57 出处:网络
What is the best way to generate C# classes for use with Castle ActiveRecord and NHibernate given an existing database structure?

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 开发者_JAVA百科class generation tools or is it just less hassle to write the classes by hand?


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:

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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消