FANDOM


The easiest way to generate your schema from your mappings is to use the NHibernate SchemaExport tool.

You can tie this in to the fluent configuration API using it's ExposeConfiguration method, which lets you deal with the actual NHibernate Configuration that SchemaExport requires.

Here's a basic example:

Fluently.Configure()
  .Database(/* database config */)
  .Mappings(/* your mappings */)
  .ExposeConfiguration(cfg =>
  {
    new SchemaExport(cfg)
      .Create(false, true);
  })
  .BuildSessionFactory();

The ExposeConfiguration method will be called after all the mappings have been added to the Configuration instance, so it can then be used by the SchemaExport tool.

This could be refactored slightly using C#'s syntactic sugar for lambdas:

Fluently.Configure()
  .Database(/* database config */)
  .Mappings(/* your mappings */)
  .ExposeConfiguration(BuildSchema)
  .BuildSessionFactory();

Where BuildSchema could be defined elsewhere as:

private void BuildSchema(Configuration cfg)
{
  new SchemaExport(cfg)
    .Create(false, true);
}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.