1

如何在 Fluent Nhibernate 中自动创建数据库模式?我的配置是:

  public static ISessionFactory CreateDatabase() {
  switch (4) {
    case 4: // Postgress
    _sessionFactory = Fluently.Configure()
      .Database(PostgreSQLConfiguration.PostgreSQL82.ConnectionString(ConnectionString))
      .ExposeConfiguration(c => {
        c.SetProperty("cache.use_second_level_cache", "false");
        c.SetProperty("cache.use_query_cache", "false");
      })
      .ExposeConfiguration(SchemaMetadataUpdater.QuoteTableAndColumns)
      .ExposeConfiguration(x => new SchemaUpdate(x).Execute(false, true))
      .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Pessoa>())
      .CurrentSessionContext<WebSessionContext>()
      .BuildConfiguration()
      .BuildSessionFactory();
    break;
  }
  _sessionFactory.Dispose();
  return _sessionFactory;
}

目前有一个使用 NpgsqlCommand 创建的方法。

4

1 回答 1

3

要使用 NHibernate 创建模式,请使用 SchemaExport 类:

Configuration cfg = ....;
new SchemaExport(cfg).Create(false, true);

NHibernate 参考中的更多详细信息,第20.1.2 节。运行该工具,以及上一节。

于 2013-08-20T11:40:42.347 回答