Code Generation - MyGeneration, CodeSmith, GAT/GAX or DSL?

I am looking to generate code based on a database structure. I want to start with a base template and add things I need to it. My goal is to auto generate the boring repetative code so I can focus on the most important areas. I have been looking at CodeSmith and MyGeneration which both have starting point templates that use Enterprise Library but I wanted to see what Microsofts approach was. Is it Guidance Automation or DSL If so does anybody have an example of how to generate DAL classes and entity classes from a database using these tools

Answer this question

Code Generation - MyGeneration, CodeSmith, GAT/GAX or DSL?

  • Dan Waters [MSFT]

    Maybe you're right.  I was thinking the partial classes took care of a lot but really don't cover everything (stored procedures & entity classes).  My idea was to generate a ton of code from a database structure (crud sp's, entity classes, web controls, form controls, etc.) and then piece things together.

    When do you think the WCSF will be released

    I see  you are using Windows Workflow Foundation.  This solution is becoming increasingly complex.  My basic goal was to increase productivity and by generating classes, stored procedures, a service layer, web controls and form controls from a database model.  Now I think I've gone too far.


  • KevinHall

    Should the Web Service Factory and the Web Client Factory use the same business object, right In a n-tier design wouldn't the web service and web client be considered the presentation layer which use the same business entities. If so should there be a Business Entity Factory
  • Ken_Bussell

    did not read your complete respons [will do] but I want to mention that there is a start for a web client factory: look at codeplex: http://www.codeplex.com/Wiki/View.aspx ProjectName=websf



  • OmegaMan

    Although very easy to use, I feel Datasets are only valuable for smaller projects and, in ASP.NET, where the number of simultaneous users are going to be low (as DataSets are in-memory representations of your database.)

    I've had success with .NetTiers (a set of CodeSmith templates) when going with a very data-centric (Domain-driven) design that might change frequentlly and where performance is a critical requirement.

    http://blogs.msdn.com/adamhems/archive/2006/03/02/542516.aspx

    You might also find the "Blinq" prototype interesting:

    http://www.asp.net/sandbox/app_blinq.aspx tabid=62

     - Adam

     


  • NP Rudra

    they both have the dataccess factory which can generate business entities from databases

    Should the Web Service Factory and the Web Client Factory use the same business object, right Could but is not necessary



  • gabo_uy

    Thanks for the responses Diego and Clemens.  I am open to any idea that helps me increase my productivity and consistency.  I am currently looking at the software factories you mention Clemens and trying to run through the lab.  I certainly like the idea.  It seems very similar to the goals of MyGeneration or CodeSmith.  I think the integration with Visual Studio and going the “Microsoft way” are big benefits.  I wish there was a website factory that could produce administrative pages and web controls using my business entities as data providers.  The main thing I like about MyGeneration and CodeSmith is that I get the templates set and press one button to generate (or regenerate) my code.  The GA approach seems to be strinning together recipies.  I guess I can write a custom recipe stringing together the others.  I think MyGeneration has a way of storing Metadata about tables/columns (column x in table y is an audit field) which help determine behavior when generating code (audit fields are read only except in the stored procedure where the query user is used and dates are autogenerated).


    Diego.  I did not look into this option only because I wanted to create stored procedures for the crud operation for security and so that I can have more places to put fundamental business logic (audit logs and to enforce record level permissions).  I don’t know that this approach takes this into account.  I guess it means dealing with most of this in the business objects and there is a decent argument to be made for this (aside from the security issue).  But sometimes I feel that the sp give me some flexibility in extending my application or dealing with a “special” circumstance (where you might use temp tables where the data storage is very different from the way the user interacts with it) of which there seem to be couple in every application.  Additionally almost all application seem to have a DAL.  Your approach may be the wave of the future but and I like being on the cutting edge but I don’t want to be on the bleeding edge.  Well that might not be fair.  I like to use things I know and add to them new techniques and tools for the next project.  This project code generation is what I want to add (along with factories) and I think the approach you specify either replaces the generation piece or adds too many new things to deal with for this project.  I don't think it can replace the generation piece because generation deals with more then just the DAL.


  • Navya Jeevan

    Hmmm... lcj:

    Is there something I missed Why isn't enough with the Visual Studio 2005 support for database schemas through ADO.NET's Strong Typed DataSet

    It would be fantastic if you can save some time to watch this webcast, MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 06 of 15): Designing the Data Access Tier, in order to learn how easy is, with Visual Studio 2005 create a strong typed DataSet which specific methods based on your own entities. 0 lines of code warrantied



  • DMottorn

    you can also find the webcast on Hummel's blog.

    A template for the template, you must be very sure about the requirements of your system... It is possible to tweak the guidance [the sources are available] so he does most of the steps automatically. I don't know if you really want to do that, you are building a system on the best practices from the Patterns team with a tweaked guidance. You must also keep a version control of the guidance within your solutions... can be hard to maintain.

    There are more packages on the way, service agents for sure.



  • Ryan G

    Release 1 of WCFS: dec. 06

    I see  you are using Windows Workflow Foundation. I'm not makking it..!

    I don't think it's going to be painfull to organize page flow and navigation with  Windows Workflow, but I hope they will organize the factory that way that you can still use it even if you don't have .NET3.0 or  don't want to use it.



  • Dr. Zoop

    the subject is: Code Generation - MyGeneration, CodeSmith, GAT/GAX or DSL

    There is a data-access guidance package available, already did some projects with it. Creating data access code based on a database schema with crud logic.

    The dataset designer is an option you may consider to use, in my opinion it's only useful within small projects, another approach is also explained in this webcast [Architecting Desktop Applications with 2.0 (Part 06 of 15): Designing the Data Access Tier] from Hummel.



  • Rob Davis38041

    Fellas,

    I’m sorry but I insist: aren’t we facing the issue from the solution perspective without considering what the problem actually was

    The original issue was "how to generate code based on a database structure" (I'm using lcj's words with no changes at all). Then, lcj claimed "but I wanted to see what Microsoft's approach was"

    I suggested a webcast with such that approach. I want to propose a new one in the same direction

    MSDN Webcast: Implementing a Data Access Layer with the Visual Studio 2005 Dataset Designer

    The Dataset Designer in the Microsoft Visual Studio 2005 development system provides a rich, interactive way of designing and coding a data access layer. In the Dataset Designer, when you declare and manage typed dataset definitions that are generated from a database, a TableAdapter is also created for each table. TableAdapters allow you to declaratively write data access code through a combination of wizards and properties. Working with typed datasets and TableAdapters, you will rarely have a need to write any ADO.NET code by hand again. This webcast explores these capabilities through numerous demos and examples. Learn how to generate typed datasets and keep them synchronized with their data source, how to create and configure TableAdapters, and how to design and support ad hoc queries. Presenter: Brian Noyes, Chief Architect, IDesign

    I just want to say something, fellas: you can find in certain ocassions more than one MS way to do the same. DSL thru Software Factories approach is awesome for any general scenario, but depending on the particular case, you can still find other possibilities

    Particularly in this case, CRUD logic generation, a typical problem we face often and every time we deal with databases, there are several approaches, MS and non MS, to deal with. You can choose anyone you like but my reco here is try to choose the easiest, more finished, more ready to use

    In this particular context, having more than one way, DSL is not a so finished, ready to use solution: you still have to create your own DSL and GAT artifacts in order to solve the initial problem (creating data access code based on database schema). Compared with VS 2005 Dataset Designer approach, already available, this last approach is by far better in terms of lcj's general project schedule

    My 0.05 cts



  • Ashley Lessard

    Look at Smart Client Software Factory and the Web Service Software Factory, there are example implementations in it... in the wssf is a guidance packages that generates data logic classes and business entities the business logic you must implement your self, of course

    It works..!



  • mfauziii

    I'm getting it right now.  I would love a system for which I could create both a web client and web services/smart client front end.  Systems need to talk to the service layer.  The smart client would duplicate most functionality in the web client but would have additional functionality that is harder to support in a web client such as active notification.

    I read through the lab on the service pattern and find that there are a lot of steps and they have to be done in a specific order.  For a specific system if I knew my selections or settings how could streamline the configuration options so that they run automatically   Like a template for the template.

    That was a long post wasn't it.  I just couldn't stop.  I could not access the data webcast but I did see the Packaging Design and Architecture Guidance for Visual Studio (Level 300).


  • Code Generation - MyGeneration, CodeSmith, GAT/GAX or DSL?