Data Access has been discontinued. Please refer to this page for more information.

How to: Create/Migrate Your Database

Once you have an instance of your context class, there are several methods you can use to automatically create a database script, see if the database exists, and/or create the database. Open the FluentModel class and add the UpdateSchema method. This method migrates your database to the latest model state.

public void UpdateSchema()
{
   var handler = this.GetSchemaHandler();
   string script = null;
   try
   {
       script = handler.CreateUpdateDDLScript( null );
   }
   catch
   {
       bool throwException = false;
       try
       {
           handler.CreateDatabase();
           script = handler.CreateDDLScript();
       }
       catch
       {
           throwException = true;
       }
       if ( throwException )
           throw;
   }
   if ( string.IsNullOrEmpty( script ) == false )
   {
       handler.ExecuteDDLScript( script );
   }
}
Public Sub UpdateSchema()
    Dim handler = Me.GetSchemaHandler()
    Dim script As String = Nothing
    Try
        script = handler.CreateUpdateDDLScript(Nothing)
    Catch
        Dim throwException As Boolean = False
        Try
            handler.CreateDatabase()
            script = handler.CreateDDLScript()
        Catch
            throwException = True
        End Try
        If throwException Then
            Throw
        End If
    End Try
    If String.IsNullOrEmpty(script) = False Then
        handler.ExecuteDDLScript(script)
    End If
End Sub

To learn how to consume your fluent model and how to execute the UpdateSchema method, check out the How to: Consume Fluent Mapping Model.