Creating database

I have followed the manual to the letter (I believe), for creating a model and creating the underlying database. I am using Delphi XE5 and SQLExpress 2008, on a Win7 64bit computer.

My problem is that although my code runs fine and without errors, the database is never created, and without any error/message output, it’s hard to figure out the issue. Here’s my code:



MyDB.pas (defining the object model):



unit MyDB;



interface



uses

Aurelius.Mapping.Attributes;



type

[Entity]

[Automapping]

TPerson = class

private

FId: integer;

FLastName: string;

FFirstName: string;

FEmail: string;

public

property Id: integer read FId;

property LastName: string read FLastName write FLastName;

property FirstName: string read FFirstName write FFirstName;

property Email: string read FEmail write FEmail;

end;



implementation



end.





Unit1.pas (just a form for creating the db):



unit Unit1;



interface



uses

Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

Vcl.Controls, Vcl.Forms, Vcl.Dialogs,Aurelius.Drivers.Interfaces, Aurelius.Drivers.dbExpress,

   Aurelius.SQL.MSSQL, Vcl.StdCtrls, FireDAC.Stan.Intf,

FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf,

FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys,

Data.DB, FireDAC.Comp.Client, FireDAC.Phys.ODBCBase, FireDAC.Phys.MSSQL,

FireDAC.Moni.Base, FireDAC.Moni.RemoteClient, FireDAC.DApt, FireDAC.Comp.UI,

FireDAC.VCLUI.Wait, Aurelius.Engine.DatabaseManager, Data.SqlExpr,

Data.DBXMSSQL, Aurelius.Schema.Messages, Aurelius.Schema.MSSQL,

Aurelius.Mapping.Setup,Aurelius.Mapping.Explorer,

Aurelius.Mapping.MappedClasses, Aurelius.Engine.ObjectManager, MyDB, Aurelius.Global.Config,

Data.FMTBcd;



type

TForm1 = class(TForm)

    Button1: TButton;

    SQLConnection1: TSQLConnection;

    procedure Button1Click(Sender: TObject);

private

    { Private declarations }

public

    { Public declarations }

end;



var

Form1: TForm1;



implementation



{$R *.dfm}



procedure TForm1.Button1Click(Sender: TObject);

var

MyConnection: IDBConnection;

DBManager: TDatabaseManager;

begin

        SQLConnection1.Connected:=true;

        MyConnection := TDBExpressConnectionAdapter.Create(SQLConnection1, False);

        DBManager := TDatabaseManager.Create(MyConnection);

        DBManager.BuildDatabase;

        SQLConnection1.Connected:=False;

        DBManager.Free;

end;





end.



It seems a quite straight-forward operation, but like I said nothing is created in the db when procedure TForm1.Button1Click is run, and no errors are thrown. The database itself already exists (empty, no tables etc).

My SQLConnection1 contains ConnectionName= ‘SQLExpressConnection’, which is a connection made though the XE5 data explorer. It has been tested ok, and I can connect with it through other components. Also since the code runs without errors I assume the connection to the db is defined ok.



Are you using TPerson class in your project? If not, the linker will remove it from the application, and Aurelius just don't know any info about it at runtime (since it doesn't even exist in the executable). In real-life applications, this rarely happens because the class will be used eventually. 

In this case, you can just use the class once (using TPerson.Create.Free for example), or in a more "formal" (but more complex) way, you can explicitly register the classes you want to use in your mapping (see http://www.tmssoftware.com.br/aurelius/doc/web/index.html?mapped_classes_.htm

Aha! No i was not using it, had not got that far yet. Was unaware that this was a restriction. I am not very familiar with Delphi, is this something that delphi does in general when compiling, or is it a behaviour from Aurelius? Seems to me like this is default behaviour? (Removing unused classes i meen).



Anyway, thanks for your input! Solved the issue just fine. :)

Yes, it's the Delphi linker. It removes anything he can that is not being used, classes methods, properties. There are some options to control this, but by default, any unused class is removed.