Reverse engineer entities from a database

The LLBLGen Pro Designer allows you to work database first (entity definitions are reverse engineered from table or view definitions) and model first (table definitions are created from entity definitions), and you can choose between them at any given time. For this tutorial, you'll use the database first functionality of the designer by reverse engineering an set of tables into entity definitions, complete with mappings.

For this tutorial it's required you have an existing database with tables available to reverse engineer. This tutorial uses SQL Server and the example database 'Northwind' but it's the same for all other databases supported by the LLBLGen Pro designer.

Retrieving relational model data

  • Start the LLBLGen Pro designer. Either use the Programs start menu, Windows search or double click the LLBLGenPro.exe in the installation folder to start the LLBLGen Pro designer.
  • To open our tutorial project, select it from the Recent Projects list on the Home Tab, or select File -> Open Project... from the main menu, or select the project from the File -> Recent Projects... menu.
  • 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-2016 Driver (SqlClient).
  • Specify the authentication information. If you're working locally and you're running the designer as administrator, you could leave WindowsAuthentication selected for Authentication Type. 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.
  • Specify the server name. For server name, specify for example myserver.domain.com or if you're working locally on a SqlExpress installation, you probably need to use .\SQLEXPRESS
  • 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. If you expand a node the driver will retrieve the tables, views, table valued functions and stored procedures, 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.
  • 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.
  • If you open the Catalog Explorer (which is might be 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 retrieved by the designer. When you click schemas, tables or their subnodes, press Ctrl-Shift-D or right-click and select Show Details to open a tab with additional meta-information of the node(s) currently selected.

You now have an LLBLGen Pro project with all the relational model data from the catalog(s) you specified, in this case Northwind, so you can design the entities without having to be connected to the database server.

Reverse engineering entities from tables

It's now time to do something useful with this meta data: map entities and other elements onto the tables and views!

  • To create entities mapped onto tables, right-click in Catalog Explorer on 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 and entity names of the entities to map on these tables. If the checkbox of an element isn't checked, use the Checking and Selecting tools in the lower left corner of the dialog to select all rows and check the checkboxes of the selected rows. You can rename entity names here if you want to and assign a groupname to one or more elements if needed. When everything looks OK, click Add to Project.
  • In the Project Explorer, all entities you've added are now present. To view all added entities to your project, please expand the Entities node below the folder icon in Project Explorer. 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 expand 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 (or press Ctrl-S) 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 and select Edit. This will open the Entity Editor. You can also double-click the entity or press Ctrl-Shift-O while the entity is selected in the Project Explorer. Check the Field mappings tab at the bottom of the entity editor to see the mapping created by the designer in the reverse engineering process.

Next step

The next step is generating source code from your project and using it in a program: Generate source code