mikus
mikus

Reputation: 3215

Fluent NHibernate - Empty Schema SQL Files

I am still quite confused about NHibernate schema export and creation. What I want to achieve is to export schema drop-create sql file AND/OR recreate database schema depending on the application configuration.

Obviously I started with

private void BuildSchema(NHConf.Configuration cfg){
   var schema = new SchemaExport(cfg);
   schema.SetOutputFile(filename);
   schema.Create(true, true);
   schema.Drop(true, true);
}

But recently I have figured out, that what actually causes my schema to recreate is NHConf.Environment.Hbm2ddlAuto set to 'create' and SchemaExport has nothing to it.

Also the files with exported SQL schema exists but they are all empty (0KB), which is my main issue, as I manage schema recreation by Hbm2ddlAuto property.

Any ideas?

EDIT: The BuildSchema method is called just before cfg.BuildSessionFactory()

I use FluentNHibernate with NH 3.1 and Oracle 11g

Upvotes: 0

Views: 891

Answers (2)

Kaspars Ozols
Kaspars Ozols

Reputation: 11

If you are using Fluent configuration, check your mapping file for:

SchemaAction.None();

In my case I commented this line and schema export to file now works!

This post moved me in the right direction: http://lostechies.com/rodpaddock/2010/06/29/using-fluent-nhibernate-with-legacy-databases/

SchemaAction.None(); The next interesting feature is SchemaAction.None(). When developing our applications I have an integration test that is used to build all our default schema. I DONT want these table to be generated in our schema, they are external. SchemaAction.None() tells NHibernate not to create this entity in the database.

Upvotes: 1

Firo
Firo

Reputation: 30813

in your method you execute drop-create and then drop and also enabled writing to database.

this is enough to create the files, make sure you set filename correctly

new SchemaExport(config)
    .SetDelimiter(";")
    .SetOutputFile(filename)
    .Create(false, false);

to create it in database, this works for me

new SchemaExport(config).Create(false, true);

Upvotes: 2

Related Questions