Step 3: Select Database Items

Click Next to go to the next page of the wizard. This displays the Select Database Items page of the wizard:

This page contains a Databases combo box that holds a list of all databases you have specified for in the business project's app.config file. If you have specified database sets in your config file these are listed in a a separate combo box.

This page also displays the database connection information specified in the project's app.config file. The Business Layer Generator uses this connection string to connect to the specified database to retrieve business rule, default, and data access information. You can manually change this string to use different authentication or connect to a completely different database.

If you have chosen to generate entities from an EDMX file, this page also contains an Entity Data Model combo box that lists all of the Entity Data Models in your project (usually just one).

When you click the Get Data button a list of tables, views, and stored procedures are retrieved from your database, and a root node is displayed in the tree view for each type of database object. You can generate business objects from any of these database objects.

If your database does not contain views or stored procedures, the corresponding root nodes are not displayed.

Selecting Database Objects

To select database objects from which to generate business classes, expand one of the root nodes, and mark the check box next to the database object you want to select:

As you select each table the Business Object Class Name, Entity Class Name, Business Rule Class Name, and Default Values Class Name text boxes display names of the classes to be generated based on the settings specified in the previous wizard page. These class names are just defaults that can be overridden by manually changing the names in the text boxes.

When the Intelligent Renaming check box is selected, changing the root portion of the Business Object Class Name automatically changes the names of the other objects accordingly.

When the Singularize check box is selected, plural table names are singularized to derive the business object class name. So, for example, Customers, becomes Customer.

Specifying Entity Property and Display Names

If you select a data column in the tree view, a Property Name and Display Name text box is displayed to the right of the tree view:

Property Name specifies the property name generated in the Entity class for the selected data column. By default, this is the same name as the data column, but you can change it to any other name you want (following the rules for property names in C# and VB .NET).

Display Name specifies the "friendly name" used when displaying messages associated with this data column (for example, in business rule messages). If you use Pascal casing in your database column names, the Business Layer Generator provides a default display name by inserting spaces between each word. So, for example, if your database column is named QuantityOnHand, the Display Name is defaulted to Quantity On Hand.

Setting Keys, Indexes, Required Data

When a data column is selected in the tree view, the Key check box is automatically selected if the column is a primary key. The Clustered and Unique index check boxes are automatically marked if the selected column is a clustered or unique index.

The Required check box is automatically checked, if the selected column is specified as NOT nullable in the database (on the theory that columns that cannot contain nulls are required fields). You can override the default setting for a column by selecting or unselecting this check box. The Required check box is disabled when you select an auto-generated primary key data column (such as identity columns) in the tree view.

The Allow Empty Value check box is automatically displayed when the Required check box is selected. If you select Allow Empty Value, a business rule is generated for the required property that allows empty values. For example, if you select this option for a string value, the generated rule allows an empty string as well as a non-empty string, but does not allow a null string. As another example, if you select this option for a numeric value, the generated rule allows zero, or a numeric value, but does not allow a null value (on nullable types).

Setting Default Values and Min/Max

The Set Default check box and Default value text box allow you to specify default value information for new records:

There are two kinds of default values--dynamic and hard-coded. Dynamic default values are specified dynamically at run time. For example, if you are creating a new Order Detail record, you will probably want to set the Order ID column of the new Order Detail record to the primary key value of the currently selected Order. This is information that can be passed in from the user interface at run time. A hard-coded default value is always the same, and doesn't change based on the context in which it is used. For example, when adding a new Order Detail item, you may want to always set the Quantity to 1.

To specify a dynamic default value, select a database column, and select the Set Default check box, leaving the Default value text box empty. To specify a hard-coded default value, select the Set Default check box, and enter the hard-coded value in the Default value text box. Note that the Default value label displays the type of the currently selected database column. If you want to specify an empty string as a hard-coded default value for a String data column, simply enter double quotes.

If you only specify hard-coded default values for a particular business object, a default values object will NOT be created for that object. Only a HookSetDefaultValues() method will be generated in the associated business object containing code that sets the default value.

By default, the Business Layer Generator sets default hard-coded values for required, value-type columns. These default values come in handy when binding business object data to user interface controls. Take the example, of binding a required boolean data column to a check box. If you don't set default values, when you create a new row the boolean data column has a null in it. Since the column is marked as required in the database, this null cannot be saved to the back end. Without default values, the end user is forced to select then unselect the check box in order to set the null to false. In contrast, when setting the boolean data column to the default value of false when creating a new row, the whole null problem is resolved.

The Set Default check box and Default value text box are disabled when you select an auto-generated primary key data column (such as identity columns) in the tree view.

The Min and Max numeric controls automatically appear when you select a column that is a string data type. They specify the minimum and maximum lengths of the string value and are automatically populated with values from the selected database column.

Generating from Tables

When you choose to generate business and data layer from a database table, you are creating a one-to-one correspondence between a business object and a database table. If your database is designed well, many of your business objects may be generated directly from tables.

The reason this works is because database tables and business objects both represent real world entities. It's just that database tables only represent the attributes or characteristics of real world entities (such as Customer name, address, phone number), but business objects represent both the attributes and behavior of real world entities. So, it's not surprising to find a one-to-one correspondence between a database table and a business object.

Generating from Views

When you choose to generate business and data layer from a view, you can create a correspondence between a business object and a single database table or multiple database tables depending on the structure of the view.

When a view is first selected, you can click the SQL button at the bottom right of the tree view to examine the SQL code associated with the view:

When you first mark a view's check box, a Specify the Table dialog is displayed:

Since it's next to impossible to consistently parse the SQL code associated with a view to determine the primary back end table associated with the view, this dialog allows you to manually specify the table. The specified table is used to determine primary key information and is used as a default when generating stored procedure code.

Generating from Stored Procedures

When you choose to generate business and data layer from a stored procedure, you can create a correspondence between a business object and a single database table or multiple database tables depending on the structure of the stored procedure.

When a stored procedure is first selected, you can click the SQL button at the bottom right of the tree view to examine the SQL code associated with the stored procedure:

You can also click the Parameters button to launch the Parameter Value Entry Form:

This form allows you to view the parameters associated with a stored procedure, and specify a value to be associated with the parameter. Since the Business Layer Generator must execute your stored procedures behind the scenes, if a particular stored procedure has required parameters, you need to specify the parameter values in this dialog before actually selecting the stored procedure's check box.

When you first mark a stored procedure's check box, a Specify the Table dialog is displayed:

Since it's next to impossible to consistently parse the SQL code associated with a stored procedure to determine the primary back end table associated with the stored procedure, this dialog allows you to manually specify the table. The specified table is used to determine primary key information and is used as a default when generating stored procedure code.

See Also:
Step 4: Data Access Layer Options


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 06/27/18
Comment or report problem with topic