如何使用Nhibernate

时间:2017-07-03 06:14:20

标签: sql-server asp.net-mvc-4 nhibernate fluent-nhibernate

我为访问连接字符串创建NH.config文件,我很好用单连接字符串,我会维护会话工厂,但我想设置两个连接字符串并使用Nhibernate会话工厂访问并在我的应用程序中维护,所以如何可以使用NHibernate吗?

以下是我的NH.config代码:

<?xml version="1.0"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory name="development">
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="connection.connection_string">Data Source=localhost;Initial Catalog=NHTest;Integrated               Security=True;</property>       
        <property name="default_schema">[NHTest].[dbo]</property>
        <property name="connection.isolation">ReadCommitted</property>
        <property name="show_sql">false</property>
        <mapping assembly="NHTestApp"/>
    </session-factory>
</hibernate-configuration>

以下是我的app.config文件,用于访问NH.config文件: -

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
  </configSections>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
  <hibernate-configuration configSource="NH.config"/>
</configuration>

0 个答案:

没有答案