Tutorial: Create an LLBLGen Pro project.
Preface
This tutorial guides you to the first steps of using LLBLGen Pro: the steps
to create a new LLBLGen Pro project from an existing database schema.
It refers to the LLBLGen Pro designer to give you a complete
from-start-to-finish experience.
Steps to create a project
Please follow the following steps to create a new LLBLGen Pro project from an existing database schema. SQL Server and 'Northwind' will be used as the targets, but you're free to select a different database type and database schema.
- Start the LLBLGen Pro designer. Either use the Programs start menu or double click the LLBLGenPro.exe in the installation folder to start the LLBLGen Pro designer.
- Select File -> New Project... or press Cntrl-N. The Create New Project dialog opens.
- Specify the name of the project, e.g. Northwind, and the name of the creator of the project, which is normally the user's name or the name of the organisation / deparment creating / owning the project. Check if the Location textbox indeed points to the folder you normally would want to save the project file to. If not, click the [...] button next to the Location
textbox to select a different folder.
- Select as target framework LLBLGen Pro Runtime Framework.
- Click the OK button. The Project Properties editor opens. Click
OK again to close the editor.
- Right-click the 'Relational Model Data' node in the Project Explorer and
select 'Add Relational Model Data from a Database'. The wizard starts.
- Select the database driver matching the database type to connect to. For this tutorial we'll connect to
SQL Server and we therefore select the SQL Server
2000/2005/2008/2012 Driver (SqlClient).
- Specify the server name. For servername, specify for example myserver.domain.com or if you're working locally on a SqlExpress installation, you probably need to use .\SQLEXPRESS
- Specify the authentication information. If you're working locally and you're running the designer as administrator, you could leave the Windows Authentication selected. If you want to connect to a remote server instance, it might be you need to specify a database account, e.g. sa and its password.
- (Optional) To test whether the connection information you entered is
correct, click Test Connection to connect to the specified server.
- Click Next.
- The SQL Server driver will now obtain all catalogs (databases) in the
SQL Server instance you connected to
as well as the schemas and tables, views and stored procedures, if you click
open a node, to which the user you used to connect with as access.
- We're creating a project on Northwind, so we'll check the checkbox in front of Northwind
in the list. This will check the 'dbo' schema and all tables, stored
procedures and views in Northwind. Click Next.
- The wizard shows the stored procedures found. Check the checkbox in
front of 'SalesByYear' and click Finish.
- LLBLGen Pro now knows enough information to obtain the meta-data for the project and will retrieve the meta data for the specified catalogs, in this case 'Northwind',
from the database server.
You now have an empty LLBLGen Pro project. It's not really
empty, it contains all the
relational model data from the catalog(s) you specified, in this case Northwind, so you can design the entities without having to connect to the database server. If you open the
Catalog Explorer (which is probably hidden away in a tab at the right edge of the LLBLGen Pro designer. Just click the tab to make it slide into view), you can browse through the meta-data just retrieved. When you click schemas, tables or their subnodes, a tab will open with the meta-information retrieved.
It's now time to do something useful with this meta data: map entities and other elements onto the tables and views!
Creating project elements
First we'll create some entities mapped onto the Northwind tables.
We'll use Database First for this tutorial, as the
main point is using the generated code.
Mapping entities
- To create entities mapped onto tables, Right-click in Catalog Explorer
the 'Northwind' node and select 'Reverse Engineer Tables to Entity
Definitions' from the context menu.
- The dialog to select which entities to create opens, showing all database tables in the catalog.
Check the checkbox at the top of the first column to check all checkboxes at once and click Add to project.
- In the Project Explorer, all entities you've added are now present. LLBLGen Pro automatically detected the relationships between the entities you've specified (if there were any FK constraints defined in the database, and Northwind has these defined). All fields are mapped by default to a table field. Please click open some entity nodes to see that the entities indeed are filled with fields and relations.
- Save your work. It's now a good time to save the project. Click File -> Save Project to save the project to the Location specified when the project was created.
- To examine an entity in detail, Right-click the entity in the Project
Explorer -> Edit... This will open the Entity Editor. You can also double-click the entity or press
cntrl-shift-O while the entity is selected in the Project Explorer.
After we've mapped some entities, we'll now map a
TypedView onto a database view, namely
Invoices.
Mapping a typed view
- To map a TypedView onto a database view, right-click the view 'Invoices'
in Catalog Explorer and select 'Reverse Engineer to Typed View
Definition(s)' from the context menu. The dialog we've already seen in step 1 when we're mapping entities pops up, however this time it shows
only the Invoices view. Check the checkbox in front of the Invoices view and click Add to project.
- In the Project Explorer the Invoices typed view has been added below the Typed Views node, including a field mapped onto each database view field. To see the TypedView in detail, right click it and select
Edit... or double click it.
- Save your project.
Mapping a stored procedure call
LLBLGen Pro also allows you to map methods to a stored procedure. In this tutorial we'll add a
Retrieval Stored Procedure call to the
SalesByYear stored procedure in Northwind
- In the Catalog Explorer, right click the stored procedure 'SalesByYear'
and select 'Create Call Definitions' from the context menu. The Reverse
Engineering dialog with the stored procedure 'SalesByYear' is shown
- Check the checkbox in front of 'SalesByYear' and click Add to project.
- Below Stored Procedure Calls in the Project Explorer, LLBLGen Pro has added the stored procedure including its parameters and how many resultsets it will return.
- Save your project.
You've now created an LLBLGen Pro project which has entities mapped onto tables, a typed view mapped onto a database view and a stored procedure call mapped onto a stored procedure. In the following tutorials we'll use this project to create a small application which will show how to use the entities, the typed view and the stored procedure in your own code.