Sync relational model data with a database
In a database-first scenario, updates are first applied to the database schema and then reverse engineered into the model. To do this, you'll use the LLBLGen Pro Designer's Sync feature.
It is used for both synchronizing the entity model with an updated database schema in your database (Database first) as well as synchronizing your relational model data in your project with an updated entity model (Model first). In this tutorial we'll be using the former, we'll using Sync to retrieve changes from your relational database and apply them to your entity model.
For this tutorial it's required you make a change to your existing database you have used to create your LLBLGen Pro project. For this tutorial it's sufficient if you add a new field to a used table and a new table with some fields.
Retrieving new relational meta 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.
- The Database-first functionality in the designer is driven by settings. It's therefore important these settings are set to the values you want to use in your project. To examine these settings, right-click the project node in Project Explorer and select Settings..., or select from the menu Project -> Settings.
- Navigate in the tree on the left to: Conventions -> Entity Model -> Database First Development and click it.
-
On the right the settings for Database First Development are shown. As this tutorial will assume you have added a new table and a new field to an in-use table, the
settings which are important are: Add new elements after relational model data sync and Add new fields after relational model data sync.
To make the designer add new elements automatically, both settings have to be set to True. This might not be what you want, in which case you have to add new elements manually. In the case of fields this can be time consuming, hence the default for Add new fields after relational model data sync is True. As it's not always needed to add new elements based on new tables immediately (e.g. you might want to map a Typed View onto a table instead of an Entity) the setting Add new elements after relational model data sync is set to False by default. For this tutorial it's OK to set it to true however. - From the menu select Project -> Sync Relational Model Data or press
F5
. The Sync tab opens. - For the catalog and schemas in your project the Sync tab shows you the current Sync sources. For database-first development these have to be set to Database. LLBLGen Pro supports mixing database sources for a database, e.g. when you want to sync views and stored procedures with the database (using database first), but your tables with the model (model first). See the Syncing relational model data section in the Designer documentation to learn more about these advanced scenarios. If the Sync sources of your catalog/schema are set to Mixed or Model, select 'Database' for these nodes to make sure they're synced with the database.
- In the list of Available Sync Tasks, there's one, enabled sync task created for you, Sync with a database. To perform it, simply click the Perform Tasks.. button. The Relational Model Data Retrieval Wizard opens. It will pre-fill the connection information with values of the last time you obtained relational data from the database server, except for a password as these aren't saved into the project file. Correct the information if needed and clicked Next.
- The SQL Server driver will now obtain all catalogs (databases) in the SQL Server instance you connected to as well as the schemas. It will pre-check all elements which are currently in the project. For this tutorial you added a new table so you have to check the checkbox of that table in the tree to make the designer pull that meta-data information. After that, click Next.
- There are no changes to the stored procedures so click Next and 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.
- After the meta-data has been retrieved, the Sync functionality will migrate your project to the new meta-data. After the migration it will show you a log of all operations it has performed. As you added a field and a table, you should have two lines in the log, one which states that a new entity is added (based on your new table) and one for that a new field has been added (based on your new field). It will also create mappings for these elements for you.
- Click Close to close the log viewer.
- Save the project using e.g.
Ctrl-S
.
Next step
The next step is generating source code from your project and using it in a program: Generate source code