Knight Data Access Layer
Synchronizing Tables VB.NET
Basic Tasks VB.NET > Creating Database Structure > Synchronizing Tables VB.NET

It is possible to create the upgrade SQL for a table or namespace, automatically synchronize the table, or synchronize an entire namespace

 

'Get the current instance of the helper

Dim db As IDataHelper = DataHelper.SessionFactory()

 

'Get the SQL to create tables for a namespace

Dim sql As String = db.GenerateNamespaceSql("AcmeCorporation.InvoiceSystem)

 

'Get the SQL to upgrade a single table

Dim sql As String = db.GenerateUpgradeTableSql(GetType(Invoice))

 

'Synchronize the tables for all the classes in a namespace

db.SynchronizeNamespaceStructure("AcmeCorporation.InvoiceSystem")

 

'Get the SQL to add missing tables and missing columns for the namespace

Dim sql As String = db.GenerateUpgradeNamespaceSql("AcmeCorporation.InvoiceSystem")

 

'Create the database if it does not exist (uses the database specified in the connection string)

'Create tables if they do not exist for a namespace

'Add columns that do not exist for corresponding classes

db.Setup("AcmeInc.Business.Entities")