Quick Objects Documentation Akal Tech Logo
Generating Business Logic Layer Classes From Database Schema
See Also

Glossary Item Box

This tutorial will walk you through each step of creating your own business logic layer classes using the Quick Objects Designer application.

Quick Objects Designer application can be used to retreive the database schema from either Oracle or SQL Server database. The schema information can then be used to modify and specify Quick Objects Framework related properties. Then this information can be saved in a project file which can be opened later for modification or code generation.

Lets start by creating a blank project in Visual Studio (or IDE of your choice). This project can be either a class library, WinForms, Web Application project or a WebServices project. Essentially any project type that you can create and use classes in! We suggest creating a class library but it is completely up to you to decide how you would like to organize your code and classes.

Let us start the Quick Objects Designer program (Available under the Start -> All Programs -> Akal Tech - Quick Objects V4 menu).

 


EnlargeClick to enlarge

 

From the Settings menu choose the "Manage Connections" menu item and now you will see the following screen.

 


EnlargeClick to enlarge

This form lets you add/modify database connections for the databases you would like to create applications for. In our case we will be connecting to the QO_SHOP database on the SQL Server Express instance. Clicking on Add New button will open another dialog that will let you enter a Name and the connection string for your database.

In our case we are going to use the QO_SHOP as the name and the appropriate connection string.

 


EnlargeClick to enlarge

After entering the Name and Connection String values click the OK button. Now we will test the connection to ensure the provided connection string actually works. Choose the appropriate database type from the "Choose database type" drop down, in our case it is SQL Server 2005. Then click on the Test button and you will get a message indicating that the connection string works or not.

 


EnlargeClick to enlarge

Click OK button to save your newly created connection.

 

Now it is time for us to create a new project by loading the QO_SHOP database schema from the database server. Click on the Projects menu and then choose Load From Database.

 


EnlargeClick to enlarge

 

Now lets choose the QO_SHOP connection string we saved earlier, and click on it in the menu. This should load the database schema into the environment.

 


EnlargeClick to enlarge

Now simply right click in the Tables list and then click on "Select All" option. This will check all the tables in the List, it will also check all the fields on all the tables. In addition (starting v4.0 or later) this option will also check all the Views, and Stored Procedures so that they can be included in the code generation as well. If you do not want a Table, View or Stored Procedure to be included just uncheck it.

 


EnlargeClick to enlarge

 


EnlargeClick to enlarge

 

Now lets specify the Project properties. Project properties are located in a Tab on the right side. If you click on the Project Properties tab you will see a screen like the ones below. 


EnlargeClick to enlarge
 

EnlargeClick to enlarge
 
 

EnlargeClick to enlarge
The three tabs called Files Path, Options and Database as seen above contain various settings that you can specify to customize the code generated by this application. In files path section you have the ability to specify the templates that you would like to use to generate the code. By default the project will contain 4 templates. You can enable/disable any of these templates or simply delete them by selecting the item and clicking delete key. We recommend that you generate all classes the very first time, but on revisions only generate the base classes, or any other files that you don't get modified by hand. This way you can create any custom code or override the functionality offered by base classes and retain your changes even after code generation. With .NET 2.0 you have another option i.e. you can create your code in a different file altogether and use the partial keyword in the class definition. This is very useful as you can regenerate all the classes and your custom functionality is always preserved in separate files.
File Paths
Create Sub Folders For Each "Owner/Schema" This check box can be used to have the designer create sub folders in the target output folder for each owner/schema.
Use Namespace For Each Owner/Schema: If this check box is checked then during code generation the designer application will use the namespace mapping specified under the Database tab.
File Naming Convention: File Naming convention can be used to specify .
Templates:

You can configure any number of templates that can produce just about anything. The included templates can product business logic classes, classes that provide strongly typed views, and turn all stored procedures into strongly typed methods.

( Template Configuration Tutorial )

Options
Namespace: All the generated classes will be inside this Namespace.
Author Name: This name will appear in the comments at the top of each generated class file.
Modification Date: If you choose Auto as the option, then the current date time value will be used in the comments. Otherwise you can choose a date of your choice.
Parent Objects Postfix: All the related (parent) objects (based on related tables that have a parent relationship) will have this value added at the end of their name.
Child Objects Postfix: All the related (child) objects (based on related tables that have a child relationship) will have this value added at the end of their name.
Base Classes Postfix: This value will be added at the end of each class's name to create the base classes.
Make Class Name First Letter Uppercase: If this is checked, all generated class names' first letter will be upper case and the rest of the letters will be in lower case.
Naming Convention For Related Object Properties:

This drop down has five choices: FieldName_RelatedTableName_OwnerName, FieldName_RelatedTableName, RelatedTableName_OwnerName, RelatedTableName, ConstraintName.

Naming convention for related object properties determines how the other objects are accessed. To explain this property we will assume that your database schema contains the following tables:

dbo.Orders, dbo.Customers

  • FieldName_RelatedTableName_OwnerName
    When this option is selected, in the Orders class a property will be created named: CustomerID_Customers_dbo
    The type of this property will be dbo.Customers and hence allowing you easy access to the information stored in the dbo.Customers object instance.
  • FieldName_RelatedTableName
    When this option is selected, in the Orders class a property will be created named: CustomerID_Customers
    The type of this property will be Customers and hence allowing you easy access to the information stored in the Customers object instance.
  • RelatedTableName_OwnerName
    This option does keep the related object property names short, however it is only suitable if you know that two tables don't have more than one foreign key constraint between them in your database. If you have more than one foreign key constraint defined between two tables, the generated code will not give you unique/accurate access to related objects.
  • RelatedTableName
    When this option is selected, in the Orders class a property will be created named: Customers
    The type of this property will be Customers and hence allowing you easy access to the information stored in the Customers object instance.
    Note: If you have more than one relation between Orders and Customers this naming convention is not suitable. For example, if you have the following two relations:
    1. Orders.CustomerID -> Customers.CustomerID
    and
    2. Orders.ReferedByID -> Customers.CustomerID
    then the "RelatedTableName" option is not appropriate. You should select any of the other options.
  • ContraintName
    This options uses the "Constraint Name" specified in the database for the relationship. This option is not our recommended choice, since many database design tools or management utilities will change the underlying name of the constraint when you use a visual designer to manage your database. Such a change will result in a new name for your properties and hence require changes to your code.  However, this option is provided for those who prefer to use these names and use great control over such meta data in their database.
Prefix For Join Methods: This value is used as a prefix when creating helper methods that let you create joins between various objects. The methods are named in this manner: JoinPrefixValue_FieldName_RelatedTableName or if you selected RelatedTableName in the naming convention the generated method name will be JoinPrefixValue_RelatedTableName.
Generate Documentation: This includes Summary xml tags inside your class files.
Source Code Target Version:

Two choices are available:

.NET 2.0 - If you want to target and use your code in Microsoft .NET 2.0 or greater. Specific features from .NET 3.5 are not available.

.NET 3.5 - If you want to target and use your code in Microsoft .NET 3.5. Code generated with this option provides built in support for WCF, and objects can be used as DataContracts.

 
It is now time to save your project before generating the classes.
 

EnlargeClick to enlarge
 
Once you have saved the project, you can reopen it anytime and work on it or use it to generate class files.

EnlargeClick to enlarge

See Also