ITeye博客

使用nhibernate访问postgreSQL数据库

lnj · 2010-04-01 15:18 · nhibernate · 编程语言 · Markdown

使用nhibernate访问postgreSQL数据库还是比较简单的,先介绍一下开发环境。

postgreSQL 8.4 NHibernate 2.1.2.4000 Npgsql 2.0.8 Npgsql是postgreSQL的.net数据库驱动,可以从这里下载。

将NHibernate所需的dll添加到引用中,然后将Npgsql驱动中的Mono.Security.dll、Npgsql.dll放到bin文件夹下。NHibernate的配置节为:


<session-factory>
        <property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
        <property name="dialect">NHibernate.Dialect.PostgreSQLDialect</property>
        <property name="connection.connection_string">、
        <!-- nhibernate给出的配置示例中,数据库链接字符串格式有误,initial catalog应改为Database -->
Server=localhost;Database=sample;User ID=postgres;Password=postgres;</property>
        <property name="proxyfactory.factory_class">
        <!-- 选择nhibernate使用的ioc框架 -->
        NHibernate.ByteCode.Spring.ProxyFactoryFactory, NHibernate.ByteCode.Spring</property>
        <property name="current_session_context_class">managed_web</property>
        <property name="hbm2ddl.auto">update</property>
        <mapping assembly="XXX"/>
</session-factory>

之后就可以编写代码访问postgreSQL数据库了。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。