Sie sind auf Seite 1von 36

NConstruct Lite - Users Manual

Version: 2.5

NConstruct Lite - Users Manual

Table of Contents
1. ....................................................................................................... .......................................................................5 NCONSTRUCT LITE .......................................................................................................5
1.1. WHO NEEDS NCONSTRUCT LITE..................................................................................................5 1.2. INPUT AND OUTPUT .....................................................................................................................5 1.3. BASIC TERMS ...............................................................................................................................5 1.3.1. Entities...............................................................................................................................5 1.3.2. Views .................................................................................................................................6 1.3.3. Namespaces........................................................................................................................6

2. 3.

.............................................................................................7 ............................................................. SYSTEM REQUIREMENTS .............................................................................................7 START.................................................................................................................8 ................................................................................................................. QUICK START .................................................................................................................8
3.1. CODE GENERATION OUTPUT .....................................................................................................13

4.

DEPTH ...................................................................................14 EPTH................................................................................... NCONSTRUCT LITE IN DEPTH ................................................................................... 14


4.1. CODE GENERATION WIZARD .....................................................................................................14 4.1.1. Saving and Restoring Settings.........................................................................................14 4.1.2. Welcome Page.................................................................................................................15 4.1.3. Database Type Selection .................................................................................................16 4.1.4. Application Settings ........................................................................................................17 4.1.5. Namespaces Definition ...................................................................................................21 4.1.6. Objects Management ......................................................................................................23 4.1.7. O-R Mapping Creation ...................................................................................................34 4.2. CODE GENERATION PROCESS .....................................................................................................35 4.3. FURTHER STEPS..........................................................................................................................36

2/36

NConstruct Lite - Users Manual

Table of Figures
Figure 1 Quick start: NConstruct Lite .....................................................................................................8 Figure 2 Quick start: Database type selection .........................................................................................8 Figure 3 Quick start: Application settings...............................................................................................9 Figure 4 Quick start: Database server not found.....................................................................................9 Figure 5 Quick start: Namespace definition..........................................................................................10 Figure 6 Quick start: Object creation and management.......................................................................11 Figure 7 Quick start: O/R mapping creation .........................................................................................12 Figure 8 Quick start: Final report ..........................................................................................................12 Figure 9 - NConstruct Lite Toolbar ..........................................................................................................14 Figure 10 Wizard: Welcome page .........................................................................................................15 Figure 11 Wizard: Database type selection page...................................................................................16 Figure 12- Wizard: Application settings ..................................................................................................17 Figure 13 Wizard: General settings section ..........................................................................................17 Figure 14 Wizard: Connection settings page for Microsoft SQL Server 2000, 2005, and 2008 ..........19 Figure 15 Wizard: Connection settings page for Oracle 9i and 10g.....................................................19 Figure 16 - Wizard: Connection settings page for MS Access.................................................................21 Figure 17 Wizard: Namespaces definition page ....................................................................................22 Figure 18 Wizard: Add namespace/group form ....................................................................................22 Figure 19 Wizard: Namespaces definition page ....................................................................................23 Figure 20 Wizard: Objects Management...............................................................................................23 Figure 21 Wizard: Setting up an entity .................................................................................................24 Figure 22 Wizard: Simple propery settings...........................................................................................25 Figure 23 Wizard: Unique ID propery settings.....................................................................................26 Figure 24 Wizard: One-to-many property settings ..............................................................................27 Figure 25 Wizard: NHibernate Component Creation Wizard.............................................................29 Figure 26 Wizard: Formula Field Properties.........................................................................................29 Figure 27 Wizard: Entity class preview.................................................................................................30 Figure 28 Wizard: HBM Preview ..........................................................................................................30 Figure 29 - Wizard: Entity equality..........................................................................................................31 Figure 30 - Wizard: Inheritance - Table per class hierarchy ..................................................................31 Figure 31 Wizard: Base class creation Wizard ......................................................................................32 Figure 32 Wizard: Setting up a View ....................................................................................................32 Figure 33 Wizard: Views and primary keys..........................................................................................33 Figure 34 Wizard: Generated Directory Structure ...............................................................................34 Figure 35 Wizard: Final report ..............................................................................................................35 Figure 36 Wizard: Generated Directory Structure ...............................................................................35

3/36

NConstruct Lite - Users Manual

Table of Tables
Table 1 Wizard: Application Settings....................................................................................................18 Table 2 Wizard: Entitiy Section Settings...............................................................................................25 Table 3 - Wizard: Entitys Simple Propert Settings .................................................................................26 Table 4 - Wizard: Entitys Unique Id Propert Settings............................................................................27 Table 5 Wizard: Entitys One to Many Propert Settings ......................................................................28 Table 6 Wizard: View Section Settings .................................................................................................33 Table 7 Wizard: Views Properties Section Settings .............................................................................33

4/36

NConstruct Lite - Users Manual

1. NConstruct Lite
NConstruct Lite is a powerful wizard-like tool for creating application's data layer source
code for NHibernate object/relational persistence and query framework. NConstruct Lite examines database's metadata and creates NHibernate HBM files, entities' source code, Microsoft Visual Studio project file, and some optional helper files.

NConstruct Lite is a derivative of more powerful NConstruct tool. Full versions of


NConstruct software produce not only object-relational mapping source code but also a fully operational client-server enterprise application for managing and presenting the data from a database in a matter of minutes.

1.1. Who Needs NConstruct Lite


The development of the majority of enterprise applications starts by designing the relational database. This is also the crucial step of application development, since it influences further development. This step is followed by mapping relational database to an object-oriented technology and creating a link between them. There are many products covering this area. NConstruct Lite currently supports NHibernate framework. One can read more about the NHibernate framework at http://nhibernate.org. If a developer needs a data layer based on NHibernate framework and does not like to waste time for writing the majority of O/R mapping files by hand, NConstruct Lite is very useful tool.

1.2. Input and Output


NConstruct Lite can be considered as a machine, which takes a relational database as its
input and creates a source code for an application, which manages this data. Like many machines, NConstruct is human driven. This means that in the process of creating the source code, developer can influence the final output.

1.3. Basic Terms


Before continuing with detailed description of NConstruct Lite, some basic terms expressing its operation must be described.

1.3.1. Entities
Entities are basically objects mapped from database. They usually represent specific record from a table or a view. They are closely related to NHibernate, which recognizes their properties through specific mapping files (HBM files), generated by NConstruct Lite.

5/36

NConstruct Lite - Users Manual

NHibernate persists these entities to the database through save and load operations.
Properties of these entities (you could also call them entity objects) usually represent column in a database table. Entities can of course be equipped with additional properties.

NConstruct Lite generates these entities during NConstruct Lite code generation process.
Developer can later add additional functionality to them. However, in order to maintain

NHibernate and NConstruct functionality for such entities, their certain properties must be
maintained (as described later in this book). It is also important to note that entities can only be generated for tables and views having primary key.

1.3.2. Views
Views are handled very similarly to tables. In fact Entities based on views do not differ from
the ones based on tables. As it is the case with tables, Entities can also be created only from views having primary key defined. If they do not have primary key defined, it can be defined during code generation process. Whatever is stated in this guide about entities applies also to views, unless noted otherwise.

1.3.3. Namespaces
Entities can be divided into several namespaces. This improves code manageability in case of
great number of tables. The division into namespaces is also performed by developer during code generation process. Entities are usually grouped according to common areas of interest they represent within enterprise application.

6/36

NConstruct Lite - Users Manual

2. System Requirements
In order to start using NConstruct Lite, the following system requirements must be met: Windows 98/NT/2000/XP/Vista/Windows 7 SQL Server 2000, SQL Server 2005, SQL Server 2008, Oracle 9i/10g, or Access 20002003 database .NET Framework 2.0 At least 512M of memory 50 MB of hard disk space

7/36

NConstruct Lite - Users Manual

3. Quick Start
This chapter is intended to give you the first taste of NConstruct Lite, by giving a step-bystep example for creating application using the well known Northwind database. All you need to follow the steps of this chapter is to have Northwind database, which comes shipped with Microsoft SQL Server 2000 or 2005.

Figure 1 Quick start: NConstruct Lite

After starting the NConstruct Lite, the Welcome page appears (Figure 1). Click Next to proceed to Database type selection page (Figure 2).

Figure 2 Quick start: Database type selection

8/36

NConstruct Lite - Users Manual

Currently, NConstruct Lite supports Microsoft SQL Server 2000, Microsoft SQL Server 2005, Microsoft SQL Server 2008, Oracle 9i and 10g, and MS Access 2000-2003 databases. Select the type of database server you have installed on your machine and which contains

Northwind example (Microsoft SQL Server 2000, Microsoft SQL Server 2005 or Microsoft SQL Server 2008) and click Next. Code Generation Wizard searches for all database servers of selected type and displays the Aplication settings page (Figure 3).

Application Figure 3 Quick start: Application settings

On the Application settings page select appropriate SQL Server instance (in case you have several instances installed) that contains Northwind example. It might happen the first server which is selected by default in SQL server drop down menu is not accessible. In such case you get the following warning (Figure 4):

Quick Figure 4 Quick start: Database server not found

If you get such warning, simply press OK button and select a different SQL server instance. In the case you get the message for a server that contains Northwind database, verify if the server is started. From the Database name list select Northwind database. Leave Trusted connection checkbox checked and Naming convention set to Standard and click Next button.

9/36

NConstruct Lite - Users Manual

NConstruct Lite will now collect Northwind database information.


Click Next to proceed to the Namespace definition page (Figure 5).

Figure 5 Quick start: Namespace definition

All generated classes representing tables in database are by default put into namespace named by the database in our case the Northwind namespace. Leave all tables and views in Northwind namespace and click Next to proceed to Object management page (Figure 6).

10/ 10/36

NConstruct Lite - Users Manual

This page enables you to adjust some NHibernate settings. At this point let us not go into details of these settings, instead we will take advantage of the fact that by default NConstruct Lite uses table names and table field names for class names and names of properties within classes.

Figure 6 Quick start: Object creation and management

For a simple quick-start sample we don't need to make any changes in this window, so just simply press Next button to proceed to O-R mapping creation page (Figure 7).

11/ 11/36

NConstruct Lite - Users Manual

O-R mapping creation page enables you to specify where generated files are going to be
created. If you do not agree that generated files are created in a default folder, change that folder.

Figure 7 Quick start: O/R mapping creation

Click Finish to start generating Northwind project and corresponding source files. This should take only a minute or less on an average machine. Upon successful generation Final report page appears (Figure 8), which informs you where the files are created. Final report page has also some useful shortcuts. To open the folder where the files were generated, click on the first link:
C:\NConstructProjects\Northwind

To open the project file with Microsoft Visual Studio (or other IDE associated with csproj extension), click on the second link:
C:\NConstructProjects\Northwind\Src\Northwind\Northwind.Server.Data\ Northwind.Server.Data.csproj

Figure 8 Quick start: Final report

12/ 12/36

NConstruct Lite - Users Manual

3.1. Code Generation Output


NConstruct Lite has created NHibernate XML files (HBM files), corresponding entities - C# source code, one Visual Studio project file, and some optional additional files, located in Components and Exceptions folders. Components folder contains some necessary core files for entities with composed Id (up to
four composed properties).

Exceptions folder contains BusinessException.cs file which can handle custom exceptions if someone choose this type of exception handling in the Application settings step.

13/ 13/36

NConstruct Lite - Users Manual

4. NConstruct Lite in Depth


After reading this chapter you will be able to fine tune your NConstruct based enterprise application. This means you will be able to do the following: Select the database from desired instance of a database server, if there are several instances installed. Define the connection type and naming conventions for a database connection. Arrange tables and entities mapped to those tables into suitable namespaces. And finally, you will be able to understand what is going on in source code generation process.

4.1. Code Generation Wizard


As mentioned earlier, NConstruct Lite is actually a code generation wizard and is designed in the way that user proceeds through pages. Each page collects specific type of information from developer before proceeding to next page. Moving back from a page discards all the data entered on that page. This represents no problem for majority of pages since the developer who uses Code Generation Wizard easily memorizes the settings entered before. However, moving back from Object management page can lead to lose a lot of work. So, be careful to set up connection settings, include suitable modules and set up namespaces correctly before proceeding to Object management page. The following chapters describe each step of the NConstruct Lite Code Generation Wizard in detail. Before proceeding with detailed description of each Code Generation Wizards step, there is one important feature to be presented and this is saving and restoring settings in the Object management page, which is, in fact, the whole database schema.

4.1.1. Saving and Restoring Settings


Code Generation Wizard enables you to save its current state and restore it later. You can save current state by clicking Save button in the NConstruct Lite toolbar (Figure 9).

Figure 9 - NConstruct Lite Toolbar

You can restore saved settings by clicking Open button in NConstruct Lite toolbar and selecting file, which contains stored settings.

14/ 14/36

NConstruct Lite - Users Manual

4.1.2. Welcome Page


Welcome page is the first page displayed, after you have started the Code Generation Wizard. It gives brief information on how to use Code Generation Wizard and how to move
through its pages.

Figure 10 Wizard: Welcome page

Simply press Next button to move to the Database type selection page.

15/ 15/36

NConstruct Lite - Users Manual

Database 4.1.3. Database Type Selection


First thing to do is to select type of database server you wish to connect to. Currently the following database servers are supported:

Microsoft SQL Server 2000 (including Microsoft SQL Server Desktop Engine MSDE) Microsoft SQL Server 2005 (including Express Edition) Microsoft SQL Server 2008 (including Express Edition) Oracle 9i and 10g (including Express Edition) MS Access 2000-2003

By selecting database server type, Code Generation Wizard knows where to look for existing databases after you have moved to the next step.

type Figure 11 Wizard: Database type selection page

16/ 16/36

NConstruct Lite - Users Manual

Select the appropriate database type and click Next to proceed to the Application settings page.

12Figure 12- Wizard: Application settings

4.1.4. Application Settings


Having selected database type in previous step, Code Generation Wizard now looks for all database servers of the selected type and obtains information on databases they contain. It then displays obtained information in Application settings page, which slightly differs depending on the database type you have selected.

Figure 13 Wizard: General settings section

For every database type there is an Application settings group where you can set the following properties:

17/ 17/36

NConstruct Lite - Users Manual

Setting Application name

Editable Yes

Description Name of your application. This name is used in default namespace name, and names of generated projects. You can choose how to handle exceptions for database values which do not allow null values, when null value is to be inserted. Generated one-to-many associations can use a Generic Collections .NET feature. NConstruct can try to auto detect the inheritance relationships in your database. If your database table contains a foreign key that is also a primary key, the entities will be treated as joined subclasses. Some applications don't need views for presenting or even updating/adding/deleting data. If you don't need database views in application's object model check this checkbox. Remove the prefix, if your table name starts with some prefix string you do not want to include it in your entity name. Remove the prefix, if your column name starts with a prefix string you do not want to include in your field and property name. By default, NConstruct will add "Entity" suffix for all entity names (e.g. if the table name is "Orders" the entity class will be named "OrdersEntity"). If you don't want to use this suffix check this check-box.

Required columns exception type

Yes

Use Generic Collections? Autodetect entity inheritance?

Yes

Yes

Exclude database views from OR mapping? Entity prefix to remove Fields/Properties prefix to remove

Yes

Yes

Yes

Do not add "Entity" suffix for entity names

Yes

Table 1 Wizard: Application Settings

2000, Microsoft SQL Server 2000, 2005 and 2008


For Microsoft SQL Server 2000, 2005, and 2008 the Connection settings section is displayed in Figure 14.

18/ 18/36

NConstruct Lite - Users Manual

2000, 2008 Figure 14 Wizard: Connection settings page for Microsoft SQL Server 2000, 2005, and 2008

You can select appropriate Microsoft SQL Server instance from the SQL Server drop down list. Search button enables you to repeat the search for existing instances of Microsoft SQL Server database if another instance was started after the last search. All databases from a selected SQL Server instance are listed in a Database name dropdown list. Select the desired database from this drop down list. You can specify that either trusted windows connection is to be used to connect to selected database by checking out Trusted connection checkbox, or you can specify that Username and Password are to be used. If you chose trusted windows connection, make sure that user running NConstruct Lite has appropriate permissions on selected database. Set Naming convention to Standard. Other options are currently not supported. If you want to check the connection string based on your settings and which will

NConstruct use to connect to your database, click on the Generate button. The connection string is displayed in the Generated connection string text-box.

Oracle Oracle 9i and 10g


For Oracle 9i and 10g databases the Connection settings page is displayed in Figure 15.

Figure 15 Wizard: Connection settings page for Oracle 9i and 10g

Enter Server/Database instance name into Server/Database instance name field. If you are using Oracle 10g Express then enter Xe (default) into Server/Database instance name field.

19/ 19/36

NConstruct Lite - Users Manual

Enter valid username and password. Oracle user "hr" with password "hr" is offered by default. Set Naming convention to ORACLE. There are also other settings grouped in the Other settings group. You can define sequence prefix in the Sequence prefix field or sequence suffix in the Sequence suffix field. In Oracle, a sequence is an object that is used to generate a number sequence. This can be useful when you need to create a unique number to act as a primary key. You can create an auto number field by using sequences.

Oracle Data Access Components (ODAC) is among NConstruct system requirements. However, if you don't have ODAC installed you can uncheck ODAC 10.2.0.2.21 installed check-box and NConstruct will try to establish a connection using an alternative approach.
For more detailed explanation about setting up an Oracle connection, please refer to an online article at: http://www.nconstruct.com/Oracle-And-NConstruct.aspx

20/ 20/36

NConstruct Lite - Users Manual

Microsoft Access Database


For Microsoft Access database the Connection settings page is displayed in Figure 16.

Figure 16 - Wizard: Connection settings page for MS Access

When using Microsoft Access database, you first have to specify mdb file containing the database. Click Search button and browse to your mdb file. Enter username and password, if your database is protected by password, otherwise leave the username and password fields blank. Set Naming convention to Standard or ORACLE, depending on your convention preferences.

4.1.5. Namespaces Definition


In the case when database contains a lot of tables and views it is useful to distribute them across several namespaces to maintain code clarity. By default all tables and views are positioned in namespace named by the application and database they belong to, namely <ApplicationName>.Server.Data.<ApplicationName>1 (e.g. Northwind.Server.Data.Northwind).

Value of the<ApplicationName> part of the namespace is obtained from Application name field on Connection settings page, which is by default set to database name (see 4.1.4 Application Settings).
1

21/ 21/36

NConstruct Lite - Users Manual

Figure 17 Wizard: Namespaces definition page

You can release tables and/or views from namespace by checking the checkboxes in front of their names in Namespaces in the application section and then clicking Release DB objects from namespace button. You can add tables and/or views to the currently selected namespace by checking checkboxes in front of their names in Available database objects section and then clicking Move DB objects to namespace button. NConstruct Lite will, along with selected tables and/or views, move also all tables and views that reference selected tables and/or views. You can create new namespaces by clicking Create namespace button. An Add namespace/group form will open enabling you to add one or more namespaces. For each namespace you must enter Namespace name and Caption.

namespace/group Figure 18 Wizard: Add namespace/group form

The actual name of a namespace will be composed by adding a prefix "<applicationname>.Server.Data." to the name you have entered. You can add multiple namespaces by clicking Add and Continue button. You can also rename a namespace by selecting it in the Namespaces in the application section and then clicking the Rename button. And finally, you can delete a namespace by selecting it in Namespaces section and then clicking Remove namespace button. Only namespaces having no tables and views can be deleted.

22/ 22/36

NConstruct Lite - Users Manual

After having successfully set up namespaces, click Next button to proceed to Objects management page.

Figure 19 Wizard: Namespaces definition page

Objects 4.1.6. Objects Management


This is very important step in Code Generation Wizard. It is usually also the most demanding step since it enables you to fine tune code which will be generated (Figure 20).

Figure 20 Wizard: Objects Management

23/ 23/36

NConstruct Lite - Users Manual

This fine-tuning enables you to set up properties of generated views and entities, which represent the data from a database, to change some NHibernate settings, and even enables you to add new calculated properties (formula properties) to any entity. The following topics describe in detail how to fine-tune your enterprise application.

Entities Entities
To set up properties and attributes of an entity2, select the desired entity in the objects tree (Figure 21).

entity Figure 21 Wizard: Setting up an entity

All settings already have assigned default values, which are obtained by NConstruct Lite from database properties of tables to which entities refer. There are two sections of settings Entity section and Properties section.

For detailed description of an entity see 1.3.1 Entities.

24/ 24/36

NConstruct Lite - Users Manual

In Entity section you can set up settings referring to the entire class representing an entity. The following settings can be applied:
Setting Class name Editable Yes Description The name of a class representing an entity mapped to a table.

NHibernate Optional3:
Select before update? Yes Should hibernate perform update only if object is actually modified? Should insert contain only not null columns? Immutable classes may not be updated or deleted by the application. This allows NHibernate to make some minor performance optimizations. Enable or disable lazy fetching. Should update contain only changed columns? Batch size for fetching instances of this class by identifier. SQL condition to be used when retrieving objects of this class. Table 2 Wizard: Entitiy Section Settings

Dynamic insert? Is immutable?

Yes Yes

Is lazy? Dynamic update? Batch size Where SQL condition

Yes Yes Yes Yes

In the Properties section you can set up settings referring to properties of the selected entity. You can edit settings of the individual property through the Edit property form by doubleclicking on the property, or by selecting the property and then clicking the Edit button.

Edit property form can be used for editing simple properties (Figure 22), unique ID
properties (Figure 23) and one-to-many properties (Figure 24).

Wizard: Figure 22 Wizard: Simple propery settings

Refer to NHibernate documentation for details.

25/ 25/36

NConstruct Lite - Users Manual

The following settings can be applied for simple properties:

Setting
Field name

Editable
No

Description
Name of a property. It is the same as name of a corresponding field in a database. Type of a property defined on the bases of database field type.

Type

No

Enumeration type

Yes

NHibernate optional4:
Generate property Yes Specifies that the value of this property is generated by the database. Default value is "Never". Default value when entity is inserted into database, which is used if property is not set. Does a field represent a foreign key? Is property used during update? All mapped properties are. If true, property's value must not be null before saving to a database. Appropriate validation with selected exception type (set in general settings page) will be generated. Is property used during insert? All mapped properties are.

Default value

No

Foreign key? Update? Required?

No No Yes

Insert?

No

Table 3 - Wizard: Entitys Simple Propert Settings

ID properties have different properties which can be seen or altered through similar edit form.

Figure 23 Wizard: Unique ID propery settings

Refer to NHiernate documentation for details

26/ 26/36

NConstruct Lite - Users Manual

The following settings can be applied for unique ID properties:

Setting
Field name

Editable
No

Description
Name of a property. It is the same as name of a corresponding field in a database. Type of a property defined on the bases of database field type. Does a field represent a primary key? Editable only if primary key is not defined for underlying table. If editable, a composite key is created, if you select several fields. Does a field represent a foreign key?

Type

No

Primary key

Yes/No

Foreign key

No

Table 4 - Wizard: Entitys Unique Id Propert Settings

One-to-many or many-to-many properties have different properties which can be seen or altered through similar edit form.

One-topropert Figure 24 Wizard: One-to-many property settings

The following settings can be applied for one-to-many or many-to-many properties:

Setting
Field name

Editable
No

Description
Name of a property. It is the same as name of a corresponding field in a database. Type of a property defined on the bases of database field type. NConstruct auto detects if set's entity extends another class and displays it in this combo-box. You can select base class as the set's entity type.

Type

No

Convert contained entity to

Yes

27/ 27/36

NConstruct Lite - Users Manual

Move to base/subclass

Yes

If class A, which has this 1-M set, extends class B you can move set definition to the class B declaration in the HBM file by selecting class B in this combo-box. NConstruct tries to select the right type of an association during the database examination process. If you want to choose different type of an association, change the value in this check-box. A bidirectional association allows navigation from both "ends" of the association. NHibernate supports two kinds of bidirectional association: one-to-many and many-to-many. Check this check-box if you want to use bidirectional association.

Is many to many association?

Is bidirectional association?

Static fetch strategy: Fetch Batch size Yes Yes Fetch strategy to be used for fetching data from database. Batch size which refers to the number of collections.

NHibernate optional5:
Where SQL condition Yes SQL condition to be used when retrieving objects of this class. Cascade action applicable for sets.

Set cascade action

Yes

Table 5 Wizard: Entitys One to Many Propert Settings

If you wish to use NHibernate managed properties like Money or Date interval on the bases of existing properties, click Manage component property button in Properties section.

Refer to NHiernate documentation for details

28/ 28/36

NConstruct Lite - Users Manual

NHibernate Component Creation Wizard guides you through component property creation
(Figure 25).

Creation Figure 25 Wizard: NHibernate Component Creation Wizard

You can also create NHibernate formula property by clicking Manage Formula Field Property button (Figure 26).

Figure 26 Wizard: Formula Field Properties

In the Formula Field Properties form there is very useful button, Execute test. Pressing this button, you can run quick SQL syntax check to test your NHibernate formula.

29/ 29/36

NConstruct Lite - Users Manual

After you have set all entitys settings and its properties settings, you can preview how an entity class will be generated by clicking Class preview button (Figure 27).

Figure 27 Wizard: Entity class preview

You can also preview how a HBM mapping file will be generated by clicking HBM preview button.

Figure 28 Wizard: HBM Preview

30/ 30/36

NConstruct Lite - Users Manual

You can set the equality condition for an entity by clicking Equality button and then selecting fields to be compared when determining equality of two entities (Figure 29).

Figure 29 - Wizard: Entity equality

Another feature supported by NConstruct Lite is support for creation of base classes. You can create base classes by the help of Table per class hierarchy wizard which leads you through base class creation.

Figure 30 - Wizard: Inheritance - Table per class hierarchy

When base class is created it usually consist of primary key fields and non nullable fields. Besides base class also subclass appears, which consists of remaining (nullable and non nullable) columns.

31/ 31/36

NConstruct Lite - Users Manual

Figure 31 Wizard: Base class creation Wizard

Views
Views are very similar to entities. The main difference is that views do not contain foreign keys and that they cannot always be updated and/or saved.

Figure 32 Wizard: Setting up a View

There are again two sections in view settings View section and Properties section.

32/ 32/36

NConstruct Lite - Users Manual

In the View section you can set the following settings of a view:

Setting
Class name

Editable
No

Description
The name of a class representing a view mapped to a database view. Table 6 Wizard: View Section Settings

In the Properties section of view settings is similar you can set the settings for individual properties of a view:

Setting
Field name

Editable
No

Description
Name of a property. It is the same as name of a corresponding field in a database. Type of a property defined on the basis of database field type. Default value when view is created (when class representing a view is instantiated).

Type Default value

No Yes

Table 7 Wizard: Views Properties Section Settings

Views and Primary Keys


Views don't have primary keys. If you want to map an entity to a view, you must specify which field in a view will be its primary key (unique identifier). By default NConstruct Lite guesses appropriate field. You can, however, set primary keys for views through Assign primary keys to a view by clicking ID assignment button. You can also set up composite primary keys, but they can be composed of not more then four fields.

Figure 33 Wizard: Views and primary keys

33/ 33/36

NConstruct Lite - Users Manual

4.1.7. O-R Mapping Creation


This is the final step before code generation process. Here you specify where you wish generated code to be located and launch generation process.

Figure 34 Wizard: Generated Directory Structure

After specifying location of generated files, click Finish button to start the code generation process.

34/ 34/36

NConstruct Lite - Users Manual

4.2. Code Generation Process


Code generation process generates your source code, copies Iesi.Collections.dll file and some necessary files. The process takes few minutes to complete on average development computer. Upon successful generation Final report page appears (Figure 35), which informs you where the files are created. Final report page has also some useful shortcuts. To open the folder where the files were generated, click on the first link:
C:\NConstructProjects\Northwind

To open the project file with Microsoft Visual Studio (or other IDE associated with sln extension), click on the second link:
C:\NConstructProjects\Northwind\Src\Northwind\NorthwindServer.sln

Figure 35 Wizard: Final report

Directory structure of generated code is formed in the way to best suite usual development environment and can easily be put under source control (e.g. Subversion). Figure 36 shows generated directory structure.

Figure 36 Wizard: Generated Directory Structure

35/ 35/36

NConstruct Lite - Users Manual

Further 4.3. Further Steps


Like suggested on the Final Report, you can search for more information, updated installation files, articles and other resources on the NConstruct web site: http://www.nconstruct.com. If you have any question, feature request or if you find a bug, you can contact NConstruct support team at support@nconstruct.com, or exchange your experience on NConstruct forums at http://www.nconstruct.com/forum/. If you need more than just O-R mapping code generation, you are invited to evaluate full

NConstruct versions which generate Windows and Web n-tier applications from your
databases with just a little more effort.

36/ 36/36

Das könnte Ihnen auch gefallen