zoukankan      html  css  js  c++  java
  • ORM Nhibernate框架在项目中的配置

    在项目中使用 Nhibernet 时,一定要将 配置文件 .xml  编译方式设置为 嵌入式资源,否则在运行项目时就会出现错误。

    以下是hibernate.cfg.xml 的配置,在配置中使用的是 Mysql 数据库

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
        <session-factory>
            <property name="dialect">NHibernate.Dialect.MySQLDialect</property>
            <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
            <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
            <property name="connection.connection_string_name">ConnectionString</property>
            <property name="connection.isolation">ReadCommitted</property>
            <property name="show_sql">false</property>
    
    
            <!-- 三种3种IoC框架动态代理方式,分别为:Castle框架、LinFu框架、Spring.Net框架。我们只要选择一种,在配置文件中配置proxyfactory.factory_class节点。-->
    
            <property name="proxyfactory.factory_class"> NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle</property>
    
            <!--<property name="proxyfactory.factory_class"> NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu</property>
    
            <property name="proxyfactory.factory_class"> NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle</property>-->
    
    
            <mapping assembly="NHibernate.Sample.Model"/>
        </session-factory>
    
    </hibernate-configuration>
    

     其中 ConnectionString 是数据库连接字符串的名称, 定义在项目启动中的 web.config 中,定义如下:

        <connectionStrings>
    
            <!--  数据库连接字符串 不可随意更改name 属性值 , 数据库连接字符connectionString属性可根据实际需要进行适当的修改-->
            <add name="ConnectionString" connectionString="server=;database=;uid=;pwd=;" providerName="MySql.Data.MySqlClient" />
        </connectionStrings>
    

     其中的 数据库对象映射文件 和对应的 mapping 文件 可以用专用的生成工具来生成 ,在此给大家推荐一个好用的生成工具: Nhibernate Mapping Genertor

    下载地址: 链接: http://pan.baidu.com/s/1gd3WpKf 密码: fgwo

  • 相关阅读:
    TEXT 6 Travelling with baggage
    TEXT 4 A question of standards
    TEXT 3 Food firms and fat-fighters
    linux——DNS服务器配置
    NISP视频知识点总结
    词根生词要打印加上汉译
    琐碎的总结 css jQuery js 等等。。。
    css 描述css reset的作用和用途。
    css--block formatting context
    《javascript高级程序设计》 第25章 新兴的API
  • 原文地址:https://www.cnblogs.com/wisdo/p/4279698.html
Copyright © 2011-2022 走看看