locked
Which Code Generator Tool have you used? suggest? RRS feed

  • Question

  • I need a code generation tool

     

    The input is a SQL Server 2000 database.

     

    Output: to generate Data Access Classes, Stored Procedures, Business Entity Classes & Business Logic classes related to the tables in database.

     

    Which tool have you used and which tool do you suggest?

    Is it worth writting a code generator tool from scratch myself or using an existing one from the web?

     

    I have seen CodeSmith, I think using that I need to create Templates or using the existing templates (which gives more flexibility as well)

     

    Another problem is maintainability, if I generate the output as described, then something in database is changed, how the code generator tool is going to manage this change?

     

    I guess I should create 2 folders in my solution

    1) "Generated": to hold the objects from the code generation

    2) "Customized": to hold the customized objects, partial classes

     

     

     

    Wednesday, April 30, 2008 6:15 PM

Answers

  • I agree with frederikm--especially his third step!  Standard templates almost never meet 100% of the need.  In most cases you will end up writing your own.  In some cases, like generating CRUD stored procedures, you will probably be able to find template that meets most of your needs, and then modify it from there.  I've never seen a template that I didn't want to modify--even the code generation you get within Visual Studio for creating new classes.

     

    Also, you could also look at T4 templates.  The runtime is included with VS 2008, and it is part of the VS 2005 and VS 2008 SDKs.  I'm a fan of CodeSmith, but I use T4 for generating code from models created using DSL Tools.  The main difference between T4 and CodeSmith is that CodeSmith has better tools for creating templates.  The downside to CodeSmith is that you have to pay a licensing fee and deal with activitating it, etc, which becomes a pain every time you build a new development environment.

    Friday, May 2, 2008 4:24 PM

All replies

  • Writing a code generation tool yourself will be pretty tedious.  Believe me, I threw one together during my first year programming, before my boss pointed out CodeSmith.  Codesmith is a good idea. Smile

    Wednesday, April 30, 2008 6:31 PM
  • Thanks David Smile

     

    I have seen NHibernate (O/R Mapper), but not sure it is easier than CodeSmith?

    I know their jobs are different but...

     

    Have you ever used CodeSmith to create an n-tier architecture application?

     

    Is there any ready or easily customizable templates?

     

    Wednesday, April 30, 2008 7:17 PM
  • CodeSmith has NHibernate templates... prople write CodeSmith templates to make their life easier...
    Wednesday, April 30, 2008 7:26 PM
  • Thanks Sheng,

     

    Do you know any good code sample of n-tier application architecture?

     

    I have used this architecture in few web services:

     

    Database

    Stored Procedures

    Business Entity Classes (more like Data Model)

    Data Access Classes

    Business Logic Classes (has 1:1 to Business Entity classes, also has some DTO)

    Presentation Logic Classes

    Web service classes

     

    I need to see other samples to make sure my architecture is good enough, probably should use LINQ where possible.

     

     

    Wednesday, April 30, 2008 7:37 PM
  • HI

     

    you have some options for code generation tools

    - codesmith

    - nettiers

    - codebreeze

    - ...

     

    if you are talking about re-genertaing code, this shouldn't pose a problem, just re execute the generation and rebuild your project..

     

    cheers

     

    F

     

    Thursday, May 1, 2008 12:18 PM
  • Thanks Fred,

     

    Do you know where I can find some code smith templates for BackEnd generation? I am having an n-tier architecture currently built.

     

    I found some on the main CodeSmith site, but weren't very useful

     

    Generally, I think it's a good investment to use a code generator tool & building the templates

    Thursday, May 1, 2008 9:16 PM
  • Hi

     

    to me the best thing to do is to

    1. create a reference case manually

    2. create the templates to use it

    3. enjoy Wink

     

    problem with the standard templates is that they're not too good (as said)

    plus if you have your own framework they don't exactly mesh..

     

    cheers

     

    F

     

    Friday, May 2, 2008 12:34 PM
  • I agree with frederikm--especially his third step!  Standard templates almost never meet 100% of the need.  In most cases you will end up writing your own.  In some cases, like generating CRUD stored procedures, you will probably be able to find template that meets most of your needs, and then modify it from there.  I've never seen a template that I didn't want to modify--even the code generation you get within Visual Studio for creating new classes.

     

    Also, you could also look at T4 templates.  The runtime is included with VS 2008, and it is part of the VS 2005 and VS 2008 SDKs.  I'm a fan of CodeSmith, but I use T4 for generating code from models created using DSL Tools.  The main difference between T4 and CodeSmith is that CodeSmith has better tools for creating templates.  The downside to CodeSmith is that you have to pay a licensing fee and deal with activitating it, etc, which becomes a pain every time you build a new development environment.

    Friday, May 2, 2008 4:24 PM
  • I would suggest you to not invest time to using the V4 templates for a few reasons.  Code generation should be compiler agnostic, but you have to thank Microsoft for implementing the feature for people to use regardless.  You may not always have access to the templates depending on your work environment.

     

    CodeSmith and CodeBreeze are both code template based, but the architecture is different.  I hated calling individual objects to generate, and having to reselect more in CodeSmith, plus pass values between templates are what I would consider ugly using the CopyPropertiesTo method to each code template.  The other concept I find a lot of CodeSmith people doing is generating off of indexes, which is wrong, because they can be removed.  So you end up doing the whole copy and paste, unless you build in your own method of doing this.

     

    CodeBreeze has sold me because everything resides in the generator itself.  CodeSmith will use Extended Properties to hold name/value pairs to be used in the code templates, but CodeBreeze has the same concept of key/value pairs inside the generator itself.  There are a whole bunch of other features in CodeBreeze that really separate it, I highly suggest you try by CodeSmith and CodeBreeze to confirm what I am saying.  CodeSmith is still a good product. 

     

    In regards to licensing, CodeBreeze has a developer's license, so when you pay for it, it's yours forever.  Time is money, it is worth it.

    Thursday, January 22, 2009 9:26 PM
  • You will also want to take a look at Viewpoints. It's a visual studio integrated modeling and code generation tool that provides customizable templates for generating any type of code. The website contains a couple of short videos that demonstrate some of its core features.
    Thursday, March 26, 2009 4:00 AM