John Kaster

Behind the Screen

Generating ECOSpace schema at runtime

leave a comment »

Robert Love and I are slapping together an ECO II ASP.NET application for the 24 Hours of Delphi Broadcast, and I wanted to create an administrator page for the application that would wipe out the current data in the database and re-generate the schema for the model, no questions asked, so we could start from scratch for our testing while developing the application.

I looked around a bit for the exact syntax for accomplishing this, but with the introduction of ECO space providers in ECO II, the code isn’t completely trivial any more. There is no default method for this primarily because most ECO applications do not require generation of the database schema at runtime. So, I managed to catch Jonas Hogstrom online, and he gave me a code snippet that got me really close. This is the Delphi version that works, on an ECO II for ASP.NET web page. You will need to add the namespace Borland.Eco.Persistence to your implementation section for the type reference to PersistenceMapperSharer to resolve correctly.


procedure TAdminForm.GenerateSchema;
var
  pmp: PersistenceMapperProvider;
  pms: PersistenceMapperSharer;
  pmdb: PersistenceMapperDb;
begin
  begin
    pms := EcoSpace.PersistenceMapper as PersistenceMapperSharer;
    pmp := PersistenceMapperProvider.GetInstance(pms.MapperProviderType);
    pmdb := pmp.PersistenceMapper;
    pmdb.CreateDataBaseSchema(EcoSpace.TypeSystemService);
  end;
end;

I hope someone else finds this code snippet handy!

Advertisements

Written by John Kaster

July 11, 2005 at 2:39 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: