EntityDAC

Database Management



When the application is created using the Code-first development approach, then any changes in the object model need to be reflected in the database structure. The TEntityConnection component provides functionality for creating and re-creating database objects based on used meta-model information.

Create database

To create the database structure, the CreateDatabase method is used. It automatically generates a DDL script based on the used meta-model, and executes the script that creates all needed database objects.

var
  Connection: TEntityConnection;
begin
  // create and initialize the connection
  // ...
  // create the database
  Connection.CreateDatabase(nil, [moCommitEachStatement]);
end;

There are a peculiarity of using this method, that should be considered: the method creates only those database objects, which are needed by the model: tables, primary and foreign keys. Any other objects that exist in the database before (triggers etc.), will not be recreated.

Drop database

To drop all the database objects used by the model, the DropDatabase method is used.

var
  Connection: TEntityConnection;
begin
  // create and initialize the connection
  // ...
  // drop the database
  Connection.DropDatabase(nil, [moCommitEachStatement]);
end;
© 1997-2024 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback