We have been evaluating a number of code generation tools recently & the one we like the best is a tool called SubSonic.
Subsonic is an open source object-relational mapper for the Microsoft .NET Framework that can really speed up the development of any software project using a database for storage.
Within minutes of completion a database design Subsonic will generate all the code for your Data Access Layer (DAL) using the ActiveRecord pattern. In addition methods to call all Stored Procedures are generated (with a single line of code). Read only objects are also created for all defined Views. In addition, Ruby-on-Rails like Scaffolds are generated giving you an instant web interface to enter test data into your database.
Subsonic also includes some time saving web controls, the most useful of which are:
QuickTable - a quick and easy way to instantly show data from a table in a read only, sortable, pageable (server paging for performance) but lightweight control (no massive viewstate here).
DropDown – in instant dropdown from any database table, no additional code required.
An intuitive query model enhances productivity and reduce even quite complex queries down to a line or two of code:
Query("Products").WHERE("CategoryID = 5").AND("UnitPrice > 10").OR("CategoryID = 1").AND("UnitPrice > 10").ExecuteReader();
Changes to your database can easily be incorporated via a web or command line based generator or for smaller sites the automatic build provider gets the job done.
The included code generation templates can easily be customised (they are simple asp.net like syntax) to cover any more specialised needs.
Having used SubSonic on a recent project (which had extremely tight deadlines) we found it an invaluable resource - reducing not only our development time, but code complexity too. We did find the odd buglet thrown in for good measure (which you may expect from a relatively new open source project) but these were quite easy to overcome & the time savings certainly outweighed these.