【问题标题】:Automatically create the schema in PostgreSQL with Fluent NHibernate使用 Fluent NHibernate 在 PostgreSQL 中自动创建模式
【发布时间】:2013-08-21 18:12:04
【问题描述】:

如何在 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 创建的方法。

【问题讨论】:

    标签: postgresql nhibernate fluent-nhibernate hbm2ddl


    【解决方案1】:

    要使用 NHibernate 创建架构,请使用 SchemaExport 类:

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

    NHibernate 参考中的更多详细信息,20.1.2. Running the tool 部分和前面的部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 2011-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多