You can just use SchemaUpdate
instead, it will update the schema if it exists and create it if it does not:
public NhibernateSessionFactory(IPersistenceConfigurer config)
{
_sessionFactory = Fluently.Configure().
Database(config).
Mappings(m => m.FluentMappings.AddFromAssemblyOf<MappingsPersistenceModel>()).
ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true)).
BuildSessionFactory();
}
One caveat: SchemaUpdate
does not do destructive updates (dropping tables, columns, etc.). It will only add them.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…