2

我有点卡在这里,无法让它工作。看起来很简单,但我一定做错了什么。

我有一个简单的类来测试 NHibernate Active Record 和 PostgreSQL,看看

[ActiveRecord]
public class Accident:ActiveRecordBase<Accident>
{
    [PrimaryKey(PrimaryKeyType.Sequence)]
    public int Id { get; set; }

    [Property]
    public string Address { get; set; }

    [Property]
    public int AddressNumber { get; set; }

    [Property]
    public testAccidentType AccidentType { get; set; }
}

public enum testAccidentType
{
    FRONT,
    BACK,
    SIDE
}

我正在尝试从我的班级创建架构,如下所示:

public class Startup
{
    public static void StartActiveRecord()
    {
        XmlConfigurationSource source = new XmlConfigurationSource(@"c:\users\h\documents\visual studio 2010\Projects\TestNHibernate\TestNHibernate\Model\config.xml");
        ActiveRecordStarter.Initialize(source, GetActiveRecordTypes());

        ActiveRecordStarter.CreateSchema();
    }

    public static Type[] GetActiveRecordTypes()
    {
        List<Type> types = new List<Type>()
        {
            typeof(Accident)
        };
        return types.ToArray();
    }
}

ActiveRecord 能够初始化这个类,但它总是卡在 CreateSchema 方法中。这是配置文件。专家有什么建议吗?

<?xml version="1.0" encoding="utf-8" ?>

<activerecord isWeb="false">
  <config>
    <add key="connection.driver_class" value="NHibernate.Driver.NpgsqlDriver" />
    <add key="connection.connection_string" value="Server=localhost;initial catalog=nhiber;User ID=postgres;Password=***;" />
    <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
    <add key="dialect" value="NHibernate.Dialect.PostgreSQLDialect" />
  </config>
</activerecord>

编辑:我想出了这个。问题是文档是错误的。PostgreSQL 不使用关键字“初始目录”,而是使用“数据库”,如下所示:

    <add key="connection.connection_string" value="Server=localhost;database=nhiber;User ID=postgres;Password=***;" />

谢谢!

4

1 回答 1

0

您需要更改连接字符串:

<add key="connection.connection_string" value="Server=localhost;database=nhiber;User ID=postgres;Password=***;" />
于 2013-03-21T07:53:36.820 回答