Talking About My Generation

Ever since I posted my article series about N-Layer design, people asked me if I use any code generators to create the basic framework for the classes used in my model. The usual answer was: yes, I do, but I use a home grown code generator for it, making it impossible to share it with others. Fortunately, that has changed....

One of the readers of my N-Layer series, named Hyzac has supplied a set of templates used for the tool My Generation, a great and very flexible open source code generator. These templates can be used to generate the VB.NET version of classes based on my N-Layer architecture. Currently, there's no C# version available.

All you need to do is place the templates (that you can download at the end of this post), put them in the Templates folder, point to a database and you're good to go. With a simple press of a button, you get the code for the BO, Bll, and Dal classes. Clean, simple, and very effective.

In fact, I got so enthusiastic by these templates and how easy they were to use, that I reevaluated My Generation and decided to start using it within Design IT, the company I work for.

Do you use any code generators to generate classes that fit within my N-Layer design model? Or do you have a different set of My Generation templates (in DotNetScript or targeting C# for example?) And do you want to share them? If so, send them to me, and I'll be happy to post them here on my site.

Note: I have looked at the MyGeneration templates and from what I have seen so far, they look fine. However, since I didn't write them, I cannot support them. If you have questions about them, I may be able to put you in contact with Hyzac.

Have fun!



The MyGeneration templates for the Bll, BO and Dal classes

Where to Next?

Wonder where to go next? You can read existing comments below or you can post a comment yourself on this article .

Consider making a donation
Please consider making a donation using PayPal. Your donation helps me to pay the bills so I can keep running Imar.Spaanjaars.Com, providing fresh content as often as possible.

Feedback by Other Visitors of Imar.Spaanjaars.Com

On Tuesday, February 5, 2008 10:52:17 AM Sundeep said:
Hi Imar!
This tool is good. By using your templates, I can only generate only vb files. Did you write templates for converting only to vb files? Please guide me, If I am wrong.
How do we create our own templates to be useful throught the project with reference to this tool.
On Tuesday, February 5, 2008 5:54:10 PM Imar Spaanjaars said:
Hi Sundeep,

Please read the post again: I did not write these templates at all!

Check out to learn how to get started with My Generation. Converting the VB version to C# shouldn't be too hard. If you have C# templates and want to share them: send them to me and I'll post them on the site.

On Wednesday, February 6, 2008 10:30:21 AM Nicolas said:
Hi Imar,

I recently wrote myself a class that retrieves the database structure and generates the code necessary for the N-Layer design, in a very similar way to the one used by the "MyGeneration templates" available here for download. In addition i wrote a web form that allowed me to customize the output.

The fact is that my code is way too much custom made, so that i don't know if it would be of an interest for the other readers. Besides, i started recently to learn LINQ to SQL which seems to bring a powerful solution to some of the problems i was facing in trying to manipulate "one to many" and "many to many" relationships that are very frequent in the relational databases i use.

But i haven't started yet to use LINQ for building real applications and i was wondering if (and how) can such a technology be added to the N-Layer design, so to make it even more powerful.

Or is it that LINQ should be considered as a completely alternative solution that has its own design patterns that could never fit into the N-Layer design ?

Im looking forward to hearing some of your thoughts on that.

On Thursday, February 7, 2008 3:38:38 PM kurt schroeder said:
Thank you for making note of the templates. this answers a question on the artical. Appreciated!!

On Thursday, February 7, 2008 9:02:56 PM Imar Spaanjaars said:
Hi Nicolas,

Yeah, I see what you're saying about your templates being "too much custom made". However, over the years I also noticed that "too custom" means "too far from what others do" and "too incompatible with others" and maybe even "too difficult to use" which in turn means you have invented a wheel that others don't need or use ;-)

Once you start generating code that others can easily reuse or adapt to, you end up with a much more flexible solution that you can benefit from as well.

Linq is not a replacement, nor only an alternative solution. Linq can certainly be used in this scenario to create a flexible data architecture. IMO, the biggest risk of Linq is that it creeps into the UI too much, causing problems that we're all trying to avoid for years. However, when used wisely, Linq can replace or at least simplify much of the data access code presented in my design.

Hope this sheds some light.


On Thursday, February 7, 2008 9:03:39 PM Imar Spaanjaars said:
Hi kurt,

You're welcome. Hope they are useful to you.

On Friday, February 8, 2008 5:43:35 AM Nicolas said:
Hi Imar,

Thanks for your answer. You're completely right about the need to write code that others can easily read and reuse. You're also right about what you call "the biggest risk of Linq". Actually, the risk is to stick to microsoft's home grown wizard/declarative and event oriented programming style and end up by losing the benefits of a better organized layer design. For example, one can be tempted to hook into the "Selected" event of a LinqDataSource in order to customize the object query and still be able to benefit from ready to use UI functionnality of controls such as a GridView (i.e. paging, sorting & CRUD). While there's nothing wrong with that, it could result in poor design that makes it harder to write a comprehensive and easy to maintain business layer.

Now, if i get you right, one would take the present N-Layer design, replace its current BusinessObject layer with one or more .dbml files (i.e. Linq O/R Mapping functionnality), than replace the DataAccess layer with, let us call it ObjectDataAccess layer performing CRUD operations as well as Join and Group By queries written directly with Linq, and than wrap those methods up in the BusinessLogic layer along with other business rules related code?

In this case, UI data access would still be done via an ObjectDataSource, and not with the newly introduced LinqDataSource.

One would also have to figure out how to automate the code generation, and also check if the code execution won't be too slow.

Does this make sense Imar, or am i wrong ?

On Sunday, February 10, 2008 8:57:45 AM Imar Spaanjaars said:
Hi Nicolas,

Yeah, that would be one way to do it. The good thing is: you can build your layers rather quick with some smart queries. Performance should be OK, as LINQ is generally pretty fast.

Downside is flexibility: you can no longer invent queries on the fly.

As an alternative, you could look into extending the LINQ DataContext as well. It's easy to add methods to it - to get specific objects or collections for example), as well as column based validation. In addition, by hooking up LINQ to stored procedures you can take care of some security related issues.

In both "worlds", you can accomplish what you want; it's merely a matter of preference and experience that tells you whether you want LINQ to be in your UI and BLL layers only.


Talk Back! Comment on Imar.Spaanjaars.Com

I am interested in what you have to say about this article. Feel free to post any comments, remarks or questions you may have about this article. The Talk Back feature is not meant for technical questions that are not directly related to this article. So, a post like "Hey, can you tell me how I can upload files to a MySQL database in PHP?" is likely to be removed. Also spam and unrealistic job offers will be deleted immediately.

When you post a comment, you have to provide your name and the comment. Your e-mail address is optional and you only need to provide it if you want me to contact you. It will not be displayed along with your comment. I got sick and tired of the comment spam I was receiving, so I have protected this page with a simple calculation exercise. This means that if you want to leave a comment, you'll need to complete the calculation before you hit the Post Comment button.

If you want to object to a comment made by another visitor, be sure to contact me and I'll look into it ASAP. Don't forget to mention the page link, or the QuickDocId of the document.

For more information about the Talk Back feature, check out this news item.