One Data Access Layer's customized LLBL class generator
page 1 of 1
Published: 13 Oct 2003
Unedited - Community Contributed
I liked the LLBL class generator but I needed it to work with my DAL (discussed in another article) and be non-SqlServer-specific and so I first got it to compile so I knew I could make any changes to what sourcecode is outputted.
by Terry Voss
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 12686/ 34

How to edit LLBL for your purposes

One Data Access Layer's LLBL Class Generator:
Author: Terry Voss

Download the zip with the class generator project and exe files:
Simply extract the zipped files into your c:\ or d:\ root using folder info and everything will go into the proper location.
Then do not create a new project, but open the project that is in the gennew folder called llblgen.csproj and that is where you will be able to edit what source code the LLBL generator generates.
The LLBL class generator is one exe windows form with 5 pages that generates one class for each database table. In this class is one property for each field of each table. Then it creates 5 methods for the class: Insert, Delete, Update, SelectOne, SelectAll. It also creates the stored procedures for these methods. To use the classes, you simply add them to your project with the project/add/addexistingitem command. To install the storedprocedures, you simply run the query that has been generated.
I liked the LLBL class generator but I needed it to work with my DAL (discussed in another article) and be non-SqlServer-specific and so I first got it to compile so I knew I could make any changes to what sourcecode is outputted. Then I found that only clsTable.cs and clsField.cs needed to be changed. I did not want to change the stored procedures, just the classes so that they efficiently as possible used the DAL. Since the program is mainly just concatenating text to write the classes, it is fairly easy to follow the code. Most of your work will be done in the clsTable.cs if you decide you want to customize the code further than I have taken the time for. If you see a method that is not in clsTable.cs then it will be in clsField.cs.
I found that there are problems if I tried to create a new c# desktop project and then add existing sourcecode items into it and then add the 2 missing references. I found it necessary to simply open the existing project and then compiling succeeded.
The two references to and system.runtime.serialization.formatters.soap are necessary for the compile. Since you are using the existing project these references already exist for you and so the project should compile without any problems. Check this before you do any editing of the .cs sourcecode files though.
The source code you are receiving is distributable as long as the comments at the start of each sourcecode file are present. The results of my changes are in the llblgen.exe that is in the \gennew\bin\debug folder. So make a shortcut to that executable and run it to generate all or a selected few tables of your database after connecting to it.
If I need to add even one field to a database, I will regenerate that class and set of stored procedures for it. You will need to delete the old sps before generating the new ones by running the associated query. (Be sure to copy any custom methods that you have added to the generated classes to a text editor before deleting old sps so you can copy them back in after regeneration)
Each class has a reference to the DAL built in so you can begin using the class methods immediately to get your data.
For example:
Dim customer as new Customer(14)
returns a reference, customer, to an object whose properties are all initialized to the customer who has id=14
customer.lastname returns Smith etc.
Dim customer as new Customer
allows you to code:
Dim dt as datatable =customer.selectall(new datatable)
now dt is a datatable object holding all customers

If you want all customers in Washington State, you will not modify the 5 basic SPs, since they may be being used by other code, but add a new SP with state parameter replacing the id parameter and name that method something like SelectState().
I've been using this DAL with this version of LLBL for about 8 months now and I really like it. Productivity is up, things are easy to maintain due to code uniformity. Data is almost as easy as desiring it. I spend almost no time on data related debugging. I have no problems with performance and I feel very well prepared for scaling any application that has this structure.
Now let's take a quick tour through the pages of the LLBL class generator.

On this page you want to enter your Sql server name which if you installed Developer's Edition with defaults would be (local) or it could be your computer's name. Then the initial catalog or database you want to run queries against. Then a valid login and password combination if you are using Sql Server credentials. If using Windows authentication you need neither.

Page two will come up automatically after connecting successfully to your database that you will be generating classes for.  All tables will be selected. At this point you will either want all the first time, or just one or a few if you are editing data structures. Use shift-select to select all and then click the toggle selected button on bottom to deselect all, then select just a few if that is your desire.

On this page you see my chosen defaults, but don't worry about the namespace. The generated classes will not have a namespace to insure that classes will import directly into your project with no namespace considerations.

On this page note I have chosen no comments, pr_ as my sp name prefix, include nocount, etc. We definitely want all 5 stored procedures. After your first run of this program, assuming you have picked all the defaults that you like, the defaults will be saved to save you time in running this so you shouldn't have to do anything on this page.

This is the last page. It is very important that you set the output to where you will be adding classes from and where your query will be so you know where your latest generation will be going into your project. At this point you click Start generation and it only takes a few seconds to get the output.

After the first time, I simply supply password and connect, then I select tables if I do not want all generated, and then erase namespace, then click on Start Generation on last page, then go add classes to project and run the query to add SPs.

Home page for LLBL class generator.
Send mail to Computer Consulting with questions or comments about this web site.
Last modified: October 10, 2003


User Comments

Title: WHo that   
Name: Kung Lao
Date: 2007-07-27 10:25:04 AM
Gotta tell ya chief, I've read both your articles and they've been very helpful.
Title: Mr   
Name: Gaurav Shah
Date: 2006-04-06 3:28:26 PM
Very helpful

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2017  |  Page Processed at 2017-03-26 9:09:16 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search