ActiveRecord、NHibernate 和 PostgreSQL
我有点被困在这里,无法让它发挥作用。这看起来很简单,但我一定做错了什么。
我有一个简单的类来测试 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=***;" />
谢谢!
I'm kinda stuck here and can't get this to work. It seems so simple, but I must be doing something incredibly wrong.
I have a simple class to test NHibernate Active Record and PostgreSQL, take a look
[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
}
And I'm trying to create the schema from my class, like this:
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 is able to initialize this class, but it's always stuck in CreateSchema method. Here is the config file. Any tips from the experts?
<?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>
EDIT: I figured this one out. the problem is that the documentation is wrong. PostgreSQL does not use the keyword "initial catalog" but it uses "database", like this:
<add key="connection.connection_string" value="Server=localhost;database=nhiber;User ID=postgres;Password=***;" />
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要更改连接字符串:
You need to change the connection string: