Tuesday, July 21, 2009

nTier .Net Code Generator

Introduction

Every one has shortage of time , every one wants short cuts. Why don't we have (being developers) short cuts to developing database applications. This is what Dot NET Code Generator tries to give you. It generates full object oriented source code and even all the forms for you using 3 layer architecture .

Background

When I started development, changing customer requirements caused me a lot of trouble.
Whenever a major change occurred I�ve to do a lot of coding to accommodate that change .After being worried for some time I decided to automate the coding process, so that I Don�t have to write repetitive coding tasks again and again.

Using the code

This Application is not developed using specific design in mind, it is developed using old style structured programming, but the code it generates is complete Object oriented which takes benefits of inheritance, polymorphism and encapsulation. All code is generated using 3 layer architecture. I�ve used meta data provided by SQL Server�s Master Database to Generate all the code . if you open master database�s sotred procedure section you�ll see a lot of stored procedures prefixed by sp_ these procedures provide you much information sufficient for our code generator .
I�ve used following stored procedures.

  • sp_databases
  • sp_tables
  • sp_Columns
  • sp_primary_keys_Rowset
  • sp_fkeys

sp_databases returns all databases attached with current instance of Sql server all these stored procedures are self explanatory , I�ll use simple �Sample � database (to explain the code) which only has two tables one tblMaster and other tblDetail .

Database is intentionally kept simple for simplicity. Once we have our database we can use sp_tables and pass our database name as argument this will return all the tables with in our database in our case tblMaster and tblDetail respectively we�ll store these tables temporarily , so that we can loop through all the tables and generate the code . Following Code snippet shows you what actually happens .


See full detail: http://www.codeproject.com/KB/aspnet/nTier__Net_Code_Generator.aspx

No comments: