Knight Data Access Layer
Synchronizing Tables
Basic Tasks C# > Creating Database Structure > Synchronizing Tables

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

IDataHelper db = DataHelper.SessionFactory();

 

//Get the SQL to create tables for a namespace

string sql = db.GenerateNamespaceSql("AcmeCorporation.InvoiceSystem);

 

//Get the SQL to upgrade a single table

string sql = db.GenerateUpgradeTableSql(typeof(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

string sql = 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");